Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how can i change a different leaderstat when the other one is at a certain point?

Asked by 6 years ago

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

0
Your if statement is fine, but you need to run that check every time the lives are updated, currently it's only being checked once when the script runs then never again. Also, LocalPlayer doesn't exist on the server. If something isn't working you should look for errors (red text) in output. You might also be interested in checking out the PlayerAdded event. gullet 471 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.

Ad

Answer this question