I’m working on a game and i want to kick the players if they play the game for 10minutes, im not a scripter so i dont know how, i searched on youtube and on the forum but didn’t find a solution. If you are a scripter please tell me how to do it.
Thanks
What I would do is create a while true loop and then using a variable do like a count down system where in the variable you have the amount of seconds (in this case it would be 600 seconds) and then just take one every loop if you are not at 0 yet.
Here is some code that should work (server script):
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(plr)
local CountDown = 20 -- Seconds they have before getting kicked (set at 10 mins)
while true do
wait(1)
if CountDown ~= 0 then
CountDown -= 1
else
plr:Kick("Time is up (10 mins has past)!") -- You can change the kick message inside of the string
break
end
end
end)
I would recommend learning how to code if your trying to make a game and don’t plan to hire someone to do it!
Why? There is no real reason why you would require it for this piece of code. I was thinking about doing it but 10 minutes is legit only 600 seconds so is not a large number and you can easily calculate minutes in seconds.
I would not massively recommend doing this in a local script, mainly because someone could if they wanted to exploit they could remove the script and stay in-game. This may not be an issue with what this user is doing but if the game is based around that you get kicked out in 10 minutes it kinda then defeats the whole point of the game.
By the way I would recommend doing what @kdopdaux1803 did rather then a loop like I did but just inside of a server script after the user gets detected cuz thinking about it the loop is pointless and takes up more resources then required.
Your point makes no sense? What do you mean, if it is a server script it will say that kick is nil? If your trying to do game.Players.LocalPlayer inside of the server script of course it is going to say nil because you can’t get the local player of a server.
Why not? There is nothing wrong with detecting when a player is added and is used lots of times in Roblox game code. All you do is detect when the player is added via the PlayerAdded event, connect it up with a function and then use the player parameter you get from the event to kick the user out when they have waited 10 minutes.
Like I said already, because exploiters can edit and delete scripts that are on the client meaning that someone could just delete the script and stay in the game longer then 10 minutes. Exploits however cannot access the server directly (the reason why we use remote events and stuff to interact with the server → client and client → server; the thing which causes clients not to be able to access the server from client is the filtering enabled which is designed exactly to stop exploiters doing things such as this.
Oh, so I did this (Yes, it’s my Button Simulator game but whatsoever, it’s fine.):
while task.wait() do
script:Clone()
script.Parent.LocalScript5:Clone()
script.Parent.Parent.StarterCharacterScripts.walkToBest:Clone()
script.Parent.Parent.StarterCharacterScripts.LocalScript:Clone()
script.Parent.Parent.StarterCharacterScripts.LocalScript2:Clone()
script.Parent.Parent.StarterCharacterScripts.LocalScript3:Clone()
script.Parent.Parent.StarterCharacterScripts.buttonSound:Clone()
end
local PlayerTimerAdded = nil
local player = nil
game.Players.PlayerAdded:Connect(plr)
player = plr
PlayerTimerAdded = tick() + amountoftimehere
end)
game:GetService("RunService").Heartbeat:Connect(function()
if player and PlayerTimerAdded and math.round(tick() - PlayerTimerAdded) == 0 then
player:Kick("time limit xd")
end
end)
You get the point. Tick is just the amount of seconds passed after January 1st 1980 smth, so adding like 20 seconds to it is just the current time + 20 seconds passed. So when the current time is the tick + number, it kicks the player. Dont really know if this is optimized but yea.