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

How do i fire a event to only the player that touched the part?

game.Players.PlayerAdded:Connect(function(Player)
	print(Player.Name)
	local debounce = false
	local function onTouched(part)
		local human = part.Parent:findFirstChild("Humanoid")
		if human ~=nil and debounce ~= true and game.Workspace.Gates.Gate1.Transporting1.Value ~= true then
			debounce = true
				game.ReplicatedStorage.Enter1:FireClient(Player)
			end
			wait(2)
			debounce = false
		end
	end
	script.Parent.Touched:connect(onTouched)
end)

It almost works but it fires it for every player how would i fix this?

1 answer

you dont need a player added event as you can get the player who touched the part(if a player did) from the touched event, so you can use this as an alternative:

local debounce = false

script.Parent.Touched:Connect(function(part)

local player = game.Players:GetPlayerFromCharacter(part.Parent)



if player and debounce ~= true and game.Workspace.Gates.Gate1.Transporting1.Value ~= true then
            debounce = true
                game.ReplicatedStorage.Enter1:FireClient(player)
          
            wait(2)
            debounce = false



  end





end)

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