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

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

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.

3 comments

0

is PlayerName a child of ReplicatedStorage as it worked fine for me when i tried your code

0

make sure PlayerName is a string value

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

2 answers

✓ Accepted answer

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.

1 comment

0

glad you got it solved

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)
	

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