Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

--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

✓ Accepted answer

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)

1 comment

0

thank you

This discussion is preserved as it was. New answers, comments, and votes are closed.