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

How do you make a part Touched function only fire from a certain player?

Asked by 4 years ago
Edited 4 years ago

Is there a way to make a touched function so that it only fires if only a certain player touches it? I tried the following:

part.Touched:connect(function(hit)
if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
    if hit.Parent == [Playername goes here] then
    --Script here
    end
end
end)

but it doesn't work. Advice? I'm still new to this kind of stuff so uh yeah..

1 answer

Log in to vote
0
Answered by
174gb 290 Moderation Voter
4 years ago
Edited 4 years ago

hit.Parent = What part of player touched

it must be:

part.Touched:connect(function(hit)
    if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
        local plr = game.Players:GetPlayerFromCharacter(hit.Parent) -- get player from character
         if plr and plr.Name == "Name Here" then
        --Script here 
        end
      end
   end
end)

i hope this works

0
worked, thank you! :D RedWirePlatinum 53 — 4y
Ad

Answer this question