okey so what i want to do is kick people when they die 5 times or more, i already tried adding things to my leaderboard script but nothing happens (when i die 5 times i dont get kick)
local Counter = "Deaths" game.Players.PlayerAdded:connect(function(Player) local leaderstats = Player:FindFirstChild('leaderstats') or Instance.new("Folder", Player) leaderstats.Name = "leaderstats" local deaths = leaderstats:FindFirstChild(Counter) or Instance.new("IntValue", leaderstats) deaths.Name = Counter deaths.Value = 0 if deaths.Value >= 5 then -- here nothing happens Player:Kick("You have died too many times!") end Player.CharacterAdded:connect(function(Character) local d = true Character:WaitForChild("Humanoid").Died:connect(function() if (d) then d = false deaths.Value = deaths.Value + 1 end end) end) end)
thats my script
You could use coroutine, if you know what that is. Or you could just do a while loop.
local Counter = "Deaths" game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local deaths = Instance.new("IntValue") deaths.Name = Counter deaths.Value = 0 deaths.Parent = leaderstats while wait() do if deaths.Value >= 5 then player:Kick("You Have Died Too Many Times!") end end end)
This is the simple way, a while loop.
Here is the coroutine way.
local Counter = "Deaths" local checkDeaths = coroutine.wrap(function(player,deaths) while wait() do if deaths.Value >= 5 then player:Kick("You Have Died Too Many Times!") end end end) game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local deaths = Instance.new("IntValue") deaths.Name = Counter deaths.Value = 0 deaths.Parent = leaderstats checkDeaths(player,deaths) end)
Either way works! Hope this helped!
local player = game.Players.LocalPlayer local char = player.CharacterAdded:Wait() local stats = player.leaderstats local deaths = stats.Deaths local remote = workspace.Script.RemoteEvent if deaths.Value == 5 then player:Kick("You have died too many times!") end
this is a local script, put it in starter pack, it should fix your issue.
This would work if not for the fact you're only checking the 'deaths' value once. You could either put a loop of some sort in to continually check the value, but that's not very efficient. It would be better to put the check right after the player dies and you increment the value.
First ditch the original check if statement on line ten.
Now change the death code instead of this:
local d = true Character:WaitForChild("Humanoid").Died:connect(function() if (d) then d = false deaths.Value = deaths.Value + 1 end end)
It could be this:
local d = true Character:WaitForChild("Humanoid").Died:connect(function() if (d) then d = false deaths.Value = deaths.Value + 1 if (deaths.Value >= 5) then --//Checking right after the player dies Player:Kick("You have died too many times!") end end end)
Far more efficient.
this works, I tested it
game.Players.PlayerAdded:Connect(function(plr) local leaderstats = Instance.new("Folder",plr) leaderstats.Name = "leaderstats" local deaths = Instance.new("IntValue",leaderstats) deaths.Name = "Deaths" deaths.Value = 0 plr.CharacterAdded:Connect(function(char) char:WaitForChild("Humanoid").Died:connect(function() deaths.Value = deaths.Value + 1 end) while true do wait() if deaths.Value >= 5 then plr:Kick("You have died too many times, "..plr.Name) end end end) end)