Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

OnTouch Script not working?

I'm trying to make it so when you touch the gold coin, the gold coin well get smaller and smaller and get removed.

local GoldCoin = script.Parent
GoldCoin.Touched:Connect(function(hit)
local p = hit.Parent:FindFirstChild("Humanoid")
if p ~= nil then	
while wait(0.1) do
GoldCoin.Mesh.Scale = GoldCoin.Mesh.Scale - Vector3.new(-0.5, -0.5, -0.5)
end
GoldCoin:remove()


2 answers

✓ Accepted answer

Please post your whole code.

IF you did post your whole code, THEN please remember to close your anonymous function by placing this at the end:

end)

If you do not end your function then the script will expect more lines of code.

Here is your fixed code ASSUMING that you included your entire script:

local GoldCoin = script.Parent
GoldCoin.Touched:Connect(function(hit)
local p = hit.Parent:FindFirstChild("Humanoid")
if p ~= nil then    
while wait(0.1) do
GoldCoin.Mesh.Scale = GoldCoin.Mesh.Scale - Vector3.new(-0.5, -0.5, -0.5)
end
GoldCoin:remove()
end)

Also, when you use:

GoldCoin:remove()

Please use:

GoldCoin:Destroy()

instead, because

:remove()

is depreciated.

Line 2

GoldCoin.Touched:Connect(function(hit)

should be

GoldCoin.Touched:connect(function(hit)

connect should not be capitalized

This discussion is preserved as it was. New answers, comments, and votes are closed.