Hey Developers,
I was tinkering around with a script I learned how to write from a tutorial and went farther than the tutorial adding rebirths and an if statement that makes XP work with rebirths to test myself to see what I can do and what I can learn from scripting on my own without someone telling me the next step.
I’ve no errors in my script, however it won’t transfer 100 XP to 1 rebirth and reset the value of XP.
This is probably just something new I don’t yet know how to do to set a value back to 0 once it reaches some value and set another value to 1 after reaching 100 in the other value.
Here’s the script:
script.Parent.ClickDetector.MouseClick:Connect(function(player)
local PlayerPoints = player.leaderstats.Points
PlayerPoints.Value = PlayerPoints.Value + 1
local PlayerXP = player.leaderstats.XP
PlayerXP.Value = PlayerXP.Value + 2
local PlayerRebirths = player.leaderstats.Rebirths
if PlayerXP.Value == 100 then
PlayerRebirths.Value = 1 and PlayerXP.Value == 0
else
PlayerRebirths.Value = 0
end
end)
Could someone point out what’s missing in my script to help me learn more? Would be highly appreciated.
Thanks for reading.
I think it is because you are using and on line 10. You can just use two different lines in the if statement. And is used for logical operators (Operators).
If you want to increase the number of rebirths each time someone gets to 100 XP you should add to the value instead of setting it to 1 (PlayerRebirths.Value += 1 instead of PlayerRebirths.Value = 1).
Try this:
script.Parent.ClickDetector.MouseClick:Connect(function(player)
local PlayerPoints = player.leaderstats.Points
PlayerPoints.Value += 1
local PlayerXP = player.leaderstats.XP
PlayerXP.Value += 2
local PlayerRebirths = player.leaderstats.Rebirths
if PlayerXP.Value == 100 then
PlayerRebirths.Value += 1
PlayerXP.Value = 0
end
end)
Let me know if something I said doesn’t make sense or if you were trying to do something else.
2 Likes
Hey thanks a lot for showing me my mistake!
You helped me realize that and, or, and not are only for boolean if statements and not for if statements like this one that change values once something occurs. Glad someone responded so I could deepen my Lua understanding some more and really build experience instead of just following tutorials and never playing around with code to find roadblocks and find the solutions to them. Also thanks for showing me that I can just use +=, makes the code look so much cleaner.
Have a great night!
1 Like