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

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

Asked by 5 years ago

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?

0
Did you check the output for errors? Spent10DollarOnAName 0 — 5y
0
yes. nothing regarding this script codingMASTER398 52 — 5y
0
Maybe a unknown global? Spent10DollarOnAName 0 — 5y

2 answers

Log in to vote
1
Answered by
Miniller 562 Moderation Voter
5 years ago
Edited 5 years ago

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!

0
it works, thanks! codingMASTER398 52 — 5y
Ad
Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
5 years ago

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!

0
i will see soon if this works codingMASTER398 52 — 5y
0
it does not /: codingMASTER398 52 — 5y
0
Oof srry Xapelize 2658 — 5y
0
I think the script is outdated :V Xapelize 2658 — 5y

Answer this question