Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

OnTouch Script not working?

Asked by 9 years ago

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

Log in to vote
2
Answered by 9 years ago

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.

Ad
Log in to vote
2
Answered by
Potlon 35
9 years ago

Line 2

GoldCoin.Touched:Connect(function(hit)

should be

GoldCoin.Touched:connect(function(hit)

connect should not be capitalized

Answer this question