so i am making a game. when you shoot a npc, it drops a coin. i am TRYING to make it give you coins and stuff when you touch it. to do that i need a
script.Parent.Touched:connect(function(player) print("touched") touched(player) end)
problem! what could be it? it does not work. i walk over the coin. zip. nada. nothing happens. whats going on?
If the script is in a part, and you're 100% sure that you touch that part, I only have 2 ideas..
First of all, try to re-design your script. Don't use connect
cuz it's deprecated, use Connect.
And it's important to tell that putting player here won't help as it only detects the part what touched it! For example, the right leg of the player! You have to do the checks first if it's really a player. Let me show you. (But this is not the issue and it should still work however)
script.Parent.Touched:Connect(function(part) if (part.Parent ~= nil and part.Parent:IsA("Model") and game.Players:FindFirstChild(part.Parent.Name)) then print("A player touched. Name: " .. part.Parent.Name) end if not (game.Players:FindFirstChild(part.Parent.Name)) then print("A part touched. Name: " .. part.Name) end end)
So just make sure that this script above is in a part. And make sure to touch that exact part!
I just giving the Lua and explain in the script because I don't know what I should say
function onTouched(part) -- when you touched print("touched") -- print touched wait(1) -- when you touched it make a cooldown script.Parent:Destroy() -- When touched the part , that part will get deleted end script.Parent.Touched:connect(onTouched) -- the function that connects by touching the part
Make the script.Parent to the part that when touched will print touched.
If you don't want the part get destroyed, delete line 4. Hope I helped. Thanks!