Search code examples
luaroblox

fix error attempt to perform arithmetic (add) on string


if (hit.Name == "Base") then return end
   hit:BreakJoints()
   if (hit.Anchored == true) then hit.Anchored = false end
   wait(.5)
   for i=1, 10 do
        hit.Transparency = hit.Transparency + 0.1
        wait(0.2)
    end
    print("removing" + hit:GetFullName()) <---- here
    hit:remove()
end
connection = script.Parent.Touched:connect(onTouched)

but i got " attempt to perform arithmetic (add) on string error "in line 10 can you fix this error pls?


Solution

  • if hit:GetFullName() is returning a string, in Lua, we use two dots .. to concatenate two strings instead of the plus +:

    print("removing " .. hit:GetFullName())