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

why this not gives a level when xp value pass 100?

Asked by
gloveshun 119
4 years ago
Edited 4 years ago
--working
game.Players.PlayerAdded:Connect(function(plr)  
    wait()
    plr.Chatted:connect(function(msg)
        if msg == "/e dance" or msg == "/e dance2" or msg == "/e dance3" then
            plr.leaderstats.XP.Value = plr.leaderstats.XP.Value + plr.leaderstats.Levels.Value
            repeat
                plr.leaderstats.XP.Value = plr.leaderstats.XP.Value + 10
                wait(5)
            until plr.Character.HumanoidRootPart.Velocity.Magnitude >= 2
        end
    end)
--not working below
while plr.leaderstats.XP.Value >= 100 do
game.ReplicatedStorage.LevelUp:FireServer()
break
end 
end)

what bad i did?

1 answer

Log in to vote
1
Answered by
NotedAPI 810 Moderation Voter
4 years ago
Edited 4 years ago

Hello, gloveshun!

You can check once a value has went above your selected value using the changed event. This event will fire everytime a value has changed. Also, you wouldn't need a remote to give the player a level as this is in a normal script.

UPDATED SCRIPT:

game.Players.PlayerAdded:Connect(function(plr)  

    plr.leaderstats.XP.Changed:Connect(function(NewValue)
        if NewValue >= 100 then
            plr:WaitForChild("leaderstats").Levels.Value = plr:WaitForChild("leaderstats").Levels.Value + 1 
        end
    end)


    plr.Chatted:connect(function(msg)
        if msg == "/e dance" or msg == "/e dance2" or msg == "/e dance3" then
            plr.leaderstats.XP.Value = plr.leaderstats.XP.Value + plr.leaderstats.Levels.Value
            repeat
                plr.leaderstats.XP.Value = plr.leaderstats.XP.Value + 10
                wait(5)
            until plr.Character.HumanoidRootPart.Velocity.Magnitude >= 2
        end
    end)

end)
0
thank you gloveshun 119 — 4y
Ad

Answer this question