local stamina = Instance.new("IntValue")
stamina.Value = 100
stamina.Value = stamina.Value - 15
-- this checks if it worked
if stamina.Value == 85 then
print("worked")
end
You’d need to either parent it somewhere you can find it, store it in a module script, or store it in _G.
Judging by the name, you’d want to parent the stamina to the player. You can do that with this:
stamina.Parent = player
You now need to get the player. You also probably want to create one for each new player. You can do that like this:
game:GetService("Players").PlayerAdded:Connect(function(player)
local stamina = Instance.new("IntValue")
stamina.Name = "Stamina"
stamina.Value = 100
stamina.Parent = player
end)
The function above runs each time a player is added to the game. You can read about this here (Handling Events).
Now when ever you want to change the stamina you can get the IntValue by finding the player. If you have the character you can get the player like this:
local character --Assume this equals the character model (rig)
local player = game:GetService("Players")
local stamina = player.Stamina --Note you might want to either check if stamina exists first to avoid an error or use :WaitForChild if you really need it (and expect it to be there).
If your stamina value is inside the player or within a folder named “leaderstats” or something, you need a type a code in server script that looks like this:
game.Players.PlayerAdded:Connect(function(player)
-- access the stamina inside player
end)