Looping a Script

I want to make this script active at all times but for some reason it is not working and this is showing in output.

Here is the script;

local Players = game:GetService("Players")
local Player = Players.LocalPlayer

while wait(1) do
	if Player.Information.XP.Value == Player.Information.XP.MaximumXP.Value then
		Player.Information.Level.Value += 1
		if Player.Information.Level.Value == 1 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 2 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 3 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 4 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 5 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 6 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 7 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 8 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 9 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 10 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 11 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 12 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 13 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 14 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 15 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 16 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 17 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 18 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 19 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 20 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
		end
		if Player.Information.Level.Value == 21 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 22 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 23 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 24 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 25 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 26 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 27 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 28 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 29 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 30 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 31 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 32 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
		end
		if Player.Information.Level.Value == 33 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 34 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 35 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 36 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 37 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 38 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 39 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 40 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 41 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 42 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 43 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 44 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 45 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 46 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 47 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 48 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 49 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 50 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 51 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 52 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 53 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 54 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 55 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 56 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 57 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 58 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 59 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 60 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 61 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 62 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 63 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 64 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 65 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 66 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 67 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 68 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 69 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 70 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 71 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 72 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 73 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 74 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 75 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 76 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 77 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 78 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 79 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 80 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 81 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 82 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 83 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 84 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 85 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 86 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 87 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 88 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 89 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 90 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 91 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 92 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 93 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 94 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 95 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 96 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 97 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 98 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 99 then
			Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			Player.Information.XP.Value = 0
		end
		if Player.Information.Level.Value == 100 then
			Player.Information.XP.MaximumXP.Value = 0
			Player.Information.XP.Value = 0
		end
	end
end
8 Likes

You can’t get the LocalPlayer from Players in a script, I see that your script is in ServerScriptService probably being a regular script. You’d need a localscript for that.

5 Likes

So I place a LocalScript inside of StarterPlayerScripts or?

1 Like

wait() has already been depreciated. Please use task.wait() instead.

3 Likes

Okay, I will change it. Thanks.

1 Like

Wait how would I make the script only activate when the Character has loaded in?

1 Like

Also, followup, heres a better script.

oldlvl = 0
game.Players.PlayerAdded:Connect(function(plr)
oldlvl = plr.Information.Level.Value
       plr.Information.Level:GetAttributeChangedSignal("Value"):Connect(function(ch)
                     if ch>oldlvl then
                           oldlvl = ch
                           Player.Information.XP.MaximumXP.Value += math.random(5, 10)
		           Player.Information.XP.Value = 0
                     end
              end)
       end)
end)
2 Likes

sorry it looks sloppy, wrote it up in devforum. lmk if it works btw

2 Likes

I will try that also is ch Character?

1 Like

ok, make sure to put it as a script in serverscriptservice as this will only work on the server

1 Like

CH is the value under level which has been changed

1 Like

Okay and would this go inside of a LocalScript inside of ServerScriptService or as a ServerScript inside of ServerScriptService?

ServerScript inside of ServerScriptService.

2 Likes

Okay thank you I will try it out now.

It didn’t work and I read your script you wrote and it looks like it only happens if the Level is changed, I want the Level up to happen if the XP is equal to the Maximum XP value.

For a LocalScript, you can simply wait for the LocalPlayer’s Appearance to load, using .CharacterAppearanceLoaded. When this is true, the Script will then run for the LocalPlayer.

.PlayerAdded works too, but this is just an alternative.

1 Like

Ah, my bad ill rewrite it. Be done in less than 5

2 Likes

Thanks a lot for your help I really appreciate it! :smile:

game.Players.PlayerAdded:Connect(function(plr)
       plr.Information.XP:GetPropertyChangedSignal("Value"):Connect(function(ch)
                     if  plr.Information.XP.Value>Player.Information.XP.MaximumXP.Value then
                           Player.Information.Level.Value += 1
                           Player.Information.XP.MaximumXP.Value += math.random(5, 10)
			               Player.Information.XP.Value = 0
                     end
              end)
       end)
end)
1 Like

Just a little note, it seems you intended to use :GetPropertyChangedSignal, but it corrected to :GetAttributeChangedSignal.

I think the OP is using values and not attributes :sweat_smile:

1 Like