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

script.Parent.Touched:connect(print("touched")) does not work?

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?

3 comments

0

Did you check the output for errors?

0

yes. nothing regarding this script

0

Maybe a unknown global?

2 answers

✓ Accepted answer

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!

1 comment

0

it works, thanks!

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!

4 comments

0

i will see soon if this works

0

it does not /:

0

Oof srry

0

I think the script is outdated :V

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