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

How to change an intvalue in a script?

Asked by 7 years ago

i need this script that changes xpneeded on each lvl ex:

game.Players.LocalPlayer.leaderstats.Level.Changed:connect(function()
       if game.Players.LocalPlayer.leaderstats.Level == 1 then
             game.Players.LocalPlayer.XpNeeded.Value = 200
       end
end)

...... if found any wrong spelling its cus i dindt copy paste

but can soemone tell me how to change an intvalue in a (local)script because idk how to

2 answers

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

you missed Value after Level and that is crucial for any value (expect when calling .Changed)

local playerdata = game.Players.LocalPlayer:WaitForChild("leaderstats")
playerdata.Level.Changed:connect(function()
       if playerdata.Level.Value == 1 then
            playerdata.XpNeeded.Value = 200
    elseif playerdata.Level.Value == 2 then
        playerdata.XpNeeded.Value = 2000 --any number you want
       end
end)

this one will change your XPNeeded to any number you want instead of using math. either way is okay. i Like defining my own exp instead of using math for it

Ad
Log in to vote
0
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

It's simple. You can just do Value = Value + Number or Value = Value - Number or Value = Value * Number (+ - / * % ^ etc.)

I suppose you want to get XpNeeded = Level * 200, we can do this with basic math.

game.Players.LocalPlayer.leaderstats.Level.Changed:connect(function()
       game.Players.LocalPlayer.XpNeeded.Value = game.Players.LocalPlayer.leaderstats.Level.Value * 200
end)

Any questions? feel free to add a comment.

0
thanks for helping me but the other answer was a little bit more helping and easy (without doing math) i do appreciate the help TigerClaws454 48 — 7y

Answer this question