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
2 years ago
Edited 2 years ago
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

Log in to vote
0
Answered by 2 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:

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)

Ad

Answer this question