I already posted a question about this, but I think I should do a better job at explaining what I'm trying to do. I am making a script that increases the difficulty depending on how many survived the round. I am doing this by checking if the "survived" stat is over 60, which is how long a round takes. But for some reason, the game always thinks the value is 0. Here is the code:
function difficultyincrease()
local players = game.Players:GetChildren()
for i = 1, #players do
local player = players[i]
if player.leaderstats.Survived.Value > 10 then
print(player.Name)
else
print(player.leaderstats.Survived.Value)
end
end
end
In the code, I changed the minimum value to 10 and replaced the difficulty increase code with debug code (print), so that I could see what the error was. Here is the entire script if it's needed:
local map = script.Parent
local backup = map:Clone()
local difficulty = game.Workspace.Difficulty
local teleport = Vector3.new(0,4,0)
function difficultyincrease()
local players = game.Players:GetChildren()
for i = 1, #players do
local player = players[i]
if player.leaderstats.Survived.Value > 10 then
print(player.Name)
else
print(player.leaderstats.Survived.Value)
end
end
end
wait(60)
map = script.Parent
map:Destroy()
map = backup:Clone()
map.Parent = game.Workspace
wait(0.5)
local plrs = game.Players:GetChildren()
for i = 1, #plrs do
local plr = plrs[i]
local stats = plr:WaitForChild("leaderstats")
local humanoidrootpart = plr.Character:FindFirstChild("HumanoidRootPart")
humanoidrootpart.CFrame = CFrame.new(teleport)
teleport = teleport + Vector3.new(0,11,0)
end
difficultyincrease()

1 comment
print(tostring(player.leaderstats.Survived.Value))--print always has string argument so player.leaderstats.Survived.Value is number, use to tostring is a solution