I have a stamina numbervalue, I want it that when the Stamina is under 20 my character would take damage but this won't work
local stamina = game.StarterPack.Stamina.Stamina.Value while game.StarterPack.Stamina.Stamina.Value < 100 do game.StarterPack.Stamina.Stamina.Value = game.StarterPack.Stamina.Stamina.Value + 10 wait(3) end while game.StarterPack.Stamina.Stamina.Value < 20 do game.Players.LocalPlayer.Character.Humanoid:TakeDamage(10) wait(1) end
I've also tried doing
game.Players.LocalPlayer.Character.Humanoid.Health = game.Players.LocalPlayer.Character.Humanoid.Health - 10
neither of them seems to work, also when trying to put the variable stamina in the while command it wouldn't work. There are no errors in Output. When Stamina is under 100 it will regen. I don't understand
A few things you need to know
1) 'Starterpack' gets cloned to the players backpack.
2) You should change health using serverscripts because local ones won't work
3) Use waitforchild
4) Values should be in the player, not inside anything else.
5) You cannot run 2 loops at once
A serverscript in workspace
game.Players.PlayerAdded:Connect(function(plr) local Stamina = instance.new('NumberValue') Stamina.Parent = plr Stamina.Name = 'Stamina' end) while wait(2) do for index, plr in pairs(game.Players:GetPlayers()) do local Stamina = plr:WaitForChild('Stamina') local char = plr.Character or plr.CharacterAdded:wait() local h = char:WaitForChild('Humanoid') if Stamina.Value < 1000 then Stamina.Value = Stamina.Value + 10 end if Stamina.Value < 20 then h:TakeDamage(20) end end end
If you have any question, just ask :)