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

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

Asked by
Catr899 12
3 years ago
Edited 3 years ago
01game.Players.PlayerAdded:Connect(function(Player)
02    print(Player.Name)
03    local debounce = false
04    local function onTouched(part)
05        local human = part.Parent:findFirstChild("Humanoid")
06        if human ~=nil and debounce ~= true and game.Workspace.Gates.Gate1.Transporting1.Value ~= true then
07            debounce = true
08                game.ReplicatedStorage.Enter1:FireClient(Player)
09            end
10            wait(2)
11            debounce = false
12        end
13    end
14    script.Parent.Touched:connect(onTouched)
15end)

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

1 answer

Log in to vote
0
Answered by 3 years ago

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:

01local debounce = false
02 
03script.Parent.Touched:Connect(function(part)
04 
05local player = game.Players:GetPlayerFromCharacter(part.Parent)
06 
07 
08 
09if player and debounce ~= true and game.Workspace.Gates.Gate1.Transporting1.Value ~= true then
10            debounce = true
11                game.ReplicatedStorage.Enter1:FireClient(player)
12 
13            wait(2)
14            debounce = false
15 
View all 24 lines...
Ad

Answer this question