My IntValue doesn't change

I’m trying to do a script that changes a value when a certain value is equal to a number.

My server script :

game.ReplicatedStorage.Remotes.Update.OnServerEvent:Connect(function(Player)
	local PlayerFolder = Player:WaitForChild("PlayerFolder")

	local XP = PlayerFolder.XP
	local RXP = PlayerFolder.RequiredXP.Value	
	local Level = PlayerFolder.Level.Value
	
	print(Level, RXP)
	
	if Level < 5 and Level > 1 then
		print("updating")
		RXP.Value = 175

	elseif Level < 15 and Level > 5 then

		RXP.Value = 250

	elseif Level < 25 and Level > 15 then

		RXP.Value = 750

	elseif Level < 50 and Level > 25 then
		RXP.Value = 1750
	elseif Level < 75 and Level > 50 then
		RXP.Value = 2500
	elseif Level < 125 and Level > 75 then
		RXP.Value = 3750
	elseif Level < 150 and Level > 125 then
		RXP.Value = 4500
	elseif Level < 250 and Level > 150 then
		RXP.Value = 5500
	elseif Level < 350 and Level > 250 then
		RXP.Value = 6500
	elseif Level < 450 and Level > 350 then
		RXP.Value = 7500
	elseif Level < 550 and Level > 450 then
		RXP.Value = 8500
	elseif Level < 650 and Level > 550 then
		RXP.Value = 9500
	elseif Level < 750 and Level > 650 then
		RXP.Value = 10500
	elseif Level < 850 and Level > 750 then
		RXP.Value = 11500
	elseif Level < 950 and Level > 850 then
		RXP.Value = 12500
	elseif Level < 1000 and Level > 950 then
		RXP.Value = 100000

	end

end)
	

And my local script :

local Player = game.Players.LocalPlayer
wait(5)
while wait() do
	game.ReplicatedStorage.Remotes.Update:FireServer(Player)
end

When I change the “Level” value in the server side the “RequiredXP” doesn’t change.

First of all using a while loop is a bad idea, your local script should be changed to:

local Player = game.Players.LocalPlayer
local lvl = Player:WaitForChild("Level")

lvl.Changed:Connect(function()
    game.replicatedstorage.remotes.update:FireServer(Player)
end)

Also you should change:

To

local RXP = PlayerFolder.RequiredXP.
1 Like

You already defined RXP as the value itself. No need to put another .Value

1 Like

It’s preferred to use GetPropertyChangedSignal rather than Changed.

1 Like

I did that and still it doesn’t update.

Lemme try to change the local script

Only when using anything but Value objects.

Let me explain, value objects .Changed method is unique compared to others because using .Changed on other type of instances will detect a change in any property, however when using ValueInstances it will only fire for changes on the Value property

If you remove the .Value from where you are setting the value of the RXP like what @Valkyrop said I’m pretty sure that will just redefine the variable, however if you change the variable like what I said in my first post and keep the .Value where you set the RXP, it should work.

Change

local Level = PlayerFolder.Level.Value
to
local Level = PlayerFolder.Level

and

if Level < 5 and Level > 1 then
to
if Level.Value < 5 and Level.Value > 1 then
1 Like
local Val = IntValue.Value

Val = 10

Will not update the Value, the Val variable does not point to the property itself it obtains the value and points to the number, so if the value IntValue.Value is 50, then its the same as saying local Val = 50
then putting Val = 10, it doesn’t actually update IntValue, what you have to do is

local Value = IntValue
Value.Value = 10

This will reference the Instance’s property allowing it to edit the Value.

1 Like

Try removing the ‘.Value’ from this line, because in all those if statements your trying to set the value of a number, instead of the IntValue called ‘RequiredXP’, and a number doesn’t have a ‘.Value’ property.

2 Likes

.Changed in Instance > Values only triggers upon change in Value, unlike any other Instances which will listen for a change in ANY property.

1 Like

Well you can do that, but the error is the RXP variable not the level.

As I said before:

1 Like

I changed and removed the .value but still it doesn’t update.

This is the current code :

game.ReplicatedStorage.Remotes.Update.OnServerEvent:Connect(function(Player)
	local PlayerFolder = Player:WaitForChild("PlayerFolder")

	local XP = PlayerFolder.XP
	local RXP = PlayerFolder.RequiredXP	
	local Level = PlayerFolder.Level
	
	print(Level.Value, RXP.Value)
	
	if Level.Value < 5 and Level.Value > 1 then
		print("updating")
		RXP.Value = 175

	elseif Level.Value < 15 and Level.Value > 5 then

		RXP.Value = 250

	elseif Level.Value < 25 and Level.Value > 15 then

		RXP.Value = 750

	elseif Level.Value < 50 and Level.Value > 25 then
		RXP.Value = 1750
	elseif Level.Value < 75 and Level.Value > 50 then
		RXP.Value = 2500
	elseif Level.Value < 125 and Level.Value > 75 then
		RXP.Value = 3750
	elseif Level.Value < 150 and Level.Value > 125 then
		RXP.Value = 4500
	elseif Level.Value < 250 and Level.Value > 150 then
		RXP.Value = 5500
	elseif Level.Value < 350 and Level.Value > 250 then
		RXP.Value = 6500
	elseif Level.Value < 450 and Level.Value > 350 then
		RXP.Value = 7500
	elseif Level.Value < 550 and Level.Value > 450 then
		RXP.Value = 8500
	elseif Level.Value < 650 and Level.Value > 550 then
		RXP.Value = 9500
	elseif Level.Value < 750 and Level.Value > 650 then
		RXP.Value = 10500
	elseif Level.Value < 850 and Level.Value > 750 then
		RXP.Value = 11500
	elseif Level.Value < 950 and Level.Value > 850 then
		RXP.Value = 12500
	elseif Level.Value < 1000 and Level.Value > 950 then
		RXP.Value = 100000

	end

end)
	

I just found the solution, the problem was that the remote was fired too many times every seconds so I replaced the local script with this :

local Player = game.Players.LocalPlayer
local lvl = Player.PlayerFolder:WaitForChild("Level")

lvl.Changed:Connect(function()
	game.ReplicatedStorage.Remotes.Update:FireServer(Player)
end)

Thank you guys for all the help, you really helped me !

1 Like