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

My in pairs loop doesn't work in my kick player script. Help?

Asked by 2 years ago
local part = script.Parent
local player = game.Players:GetChildren()
local debounce = false
part.Touched:Connect(function(part)
    if debounce == false then
        debounce = true
        print("e")
        game.ReplicatedStorage.shoot.Playing = true
        for i, v in pairs(player) do
            print("ee")
            v.PlayerGui.Guiii.blackscreen.BackgroundTransparency = 0
            wait(0.1)
            v:Kick("u lose haha")
        end
    end
end)

It all works until the in pairs loop. It also doesn't play the sound before it. If you want to know anything else comment then I will respond.

2 answers

Log in to vote
0
Answered by 2 years ago

Use Players:GetPlayers instead of Instance:GetChildren. Also, you need to call the function inside the event as the player variable was set when the script started, and variables to not automatically update.

0
Thanks! NeoDogez 18 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

I would recommend changing line 8 from game.ReplicatedStorage.shoot.Playing = true to game.ReplicatedStorage.shoot:Play() as you said the code stopped working after that. Hope that not only plays the sound but fixes your problem!

Answer this question