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

How do i make a player touch a part which enables a script in ServerScriptService?

Asked by 3 years ago

I'm having trouble fixing this problem, the script enables itself without the player touching the part. Here's the script (not localscript) script.Parent.Touched:Connect(function(touch) game.ServerScriptService.Handler.Disabled = false end) This is probably a really easy thing to fix but I'm an idiot soo...

1 answer

Log in to vote
0
Answered by 3 years ago

Hi! It runs the code with out a player touching it because the touched event fires when anything touches it not just player. Luckily you can easily check if its a player with a simple if statement.

Example:

script.Parent.Touched:Connect(function(touch) 
    if touch and touch.Parent.Humanoid then
        --Your code here
    end
end)
0
This should be more better: if touch and touch.Parent:FindFirstChild('Humanoid') then AProgrammR 398 — 3y
Ad

Answer this question