game.Players.PlayerAdded:Connect(function(player)
kills = player:WaitForChild("leaderstats").kills
kills.Changed:Connect(function(newValue)
if newValue >= 31 then
print("Player won the round")
end
end)
end)
Yes, you can use a Value.Changed event instead of doing a loop to check for when the value hits your determined amount and then send your events/end the round.
Edit: personally, I’d use a for loop to check all the players kill values on the server and only fire a remote event if I was updating a GUI. This keeps everything more secure as the count stays on the server at all times.
local Leaderstats = game.Players.LocalPlayer:WaitForChild("leaderstats"):WaitForChild("kills") -- Kills is Leaderstats Name
Leaderstats:GetPropertyChangedSignal("Value"):Connect(function()
if Leaderstats.Value == 31 then
print("Value is 31 - Game End")
end
end)
This should be a LocalScript.
Instead of a Loop, Use GetPropertyChangedSignal.
Also, Make Sure That Your Stats Name is kills with a Small k.
If Not, Change the
local Leaderstats = game.Players.LocalPlayer:WaitForChild(“leaderstats”):WaitForChild(“kills”)
To
local Leaderstats = game.Players.LocalPlayer:WaitForChild(“leaderstats”):WaitForChild(“Kills”)
This shouldn’t be handled on the client. It would make the game extremely vulnerable to exploiters who want to win the game for themselves. Using a loop to check the players leader stat values on the server and finding the winner that way is a lot more reliable @HHeartlessHunteR
This issue is different than enough from that topic that it shouldn’t be included, please don’t bring any unrelated topics into this one. Just a fourm tip.
Well If That’s the Case, He Can Use A Couple of Ways Too.
local PlayerWhoWon -- Blank Variable
while wait() do
if PlayerWhoWon == nil then -- No Winner Yet
for _, LocalPlayer in pairs(game.Players:GetChildren()) do
if LocalPlayer:FindFirstChild("leaderstats") then
if LocalPlayer.leaderstats:FindFirstChild("Kills") then -- Capital K
if LocalPlayer.leaderstats.Kills.Value == 31 then -- Capital K | 31 Kills
PlayerWhoWon = LocalPlayer.Name -- Set The Variable to The Winners Name
break -- Break Loop
end
end
end
end
else
break -- Break the Loop if Found a winner
end
end
I would use this. Server script in SeverScriptService.
for i,v in pairs(game.Players:GetChildren()) do
local leaderstats = v:WaitForChild("leaderstats")
local kills = leaderstats:WaitForChild("kills")
kills.Changed:connect(function()
if kills == 31 then
--do whatever you wanna do
end
end
end
Might be some minor errors since I typed this out from memory.
Are you changing the value from the client or server side? It has to be the server to work. Also, what are the errors in the output if you have any from the script I gave you?