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

How do you make it so the game kicks everyone when a condition is met?

Asked by 4 years ago
Edited 4 years ago

So basically I have this game where you go around collecting stuff. I don't have an idea on what I do for when everyone finds the objects, so I'm just trying to make the game kick everyone when all the objects have been found.

Here is my script

local player = game:GetService("Players")
local RS = game.ReplicatedStorage
local PN = RS.PlayerName

if PN.Value  == "Restarting..." then
    wait(10)
    for i, player in pairs(player:GetPlayers()) do 
        player:Kick("Game has ended!")
    end 
end

BTW the PN part isnt only for playerName, its a StringValue that changes the text of a label I have in StarterGUI, so i'm basically trying to make it so when the text is saying "Restarting..." wait 10 seconds then kick everyone but when i'm testing the game it doesn't kick. I'm not to familiar with using :Kick so I could just be doing something wrong.

0
is PlayerName a child of ReplicatedStorage as it worked fine for me when i tried your code HappyJakeyBoy 67 — 4y
0
make sure PlayerName is a string value HappyJakeyBoy 67 — 4y
0
Yes, PlayerName is a string value and PlayerName is also a child of ReplicatedStorage, if that were the case I would have gotten an error, but the problem is i'm not getting any errors soo Phase_Venom 55 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

So basically I was just being an idiot. I thought I had to make a whole new script so it could kick someone when the test said "Restarting" but all I had to do was go into my local script for the textLabel and basically say this

if BC.Value == 6 then
            script.Parent.Text = ReplicatedStorage.Restart.Value
            wait(3)
            local player = game:GetService("Players")
            for i, player in pairs(player:GetPlayers()) do
                player:Kick("Game is Over")
            end
        end

I thought you could only use

local player = game:GetService("Players")

In a normal script and

local player = game.Player.LocalPlayer

For a local script.

Well this whole thing was just me being dumb lol.

0
glad you got it solved royaltoe 5144 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Well you can listen to the StringValue .Changed event to detect if the StringValue has changed and then proceed accordingly.

StringValue.Changed:Connect(function()
    --Do stuff
end)

I'd recommend doing it this way though.

StringValue:GetPropertyChangedSIgnal("Value"):Connect(function()
    --Do stuff
end)

Answer this question