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

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

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

✓ Accepted answer

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

1 comment

0

worked, thank you! :D

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