i have a script which takes away 1 life ("Lives" is a leaderstat in my game) when a player dies, but i need to make it revert the players stage back to 1 and give them 25 lives again when their Lives are at 0. heres the code i tried (in serverscriptservice)
--variables local player = game.Players.LocalPlayer local lives = player.leaderstats.Lives local stage = player.leaderstats.Stage if player.lives.Value < 1 then lives.Value = lives.Value + 25 stage.Value = 1 end
thanks
You can't use LocalPlayer in ServerScripts, as they don't exist. Also, you can use the Changed function to check whether their lives reduce, and then set their stage back to one.
local Players = game:GetService("Players") Players.PlayerAdded:Connect(function(plr) local leaderstats = plr:WaitForChild('leaderstats') local Lives = leaderstats:FindFirstChild('Lives') local Stage = leaderstats:FindFirstChild('Stage') Lives.Changed:Connect(function() if Lives.Value <= 0 then Stage.Value = 1 end end) end)
Try that. I'm on mobile so I'm not too sure it will work.