Variable change not being detected

Good Afternoon fellow Roblox Developers! I have just recently been allowed access to the Roblox the development forum and unfortunately must come to you all with a bug or issue that I cant seem to get over. I’m trying to make a basic level system that will increase levels when detecting a certain amount of experience has been reached. Sounds simple enough right? Well not for me it seems.

Below I’ve attached my very basic code that doesnt seem to work.
This script is located in the ServerScriptService.

game.Players.PlayerAdded:Connect(function(player)
	
	
	local leader = Instance.new("Folder")
	leader.Name = "leaderstats"
	leader.Parent = player
	
	local lvl = Instance.new("IntValue")
	lvl.Name = "Level"
	lvl.Parent = player:WaitForChild("leaderstats")
	
	local xp = Instance.new("IntValue")
	xp.Name = "Experience"
	xp.Parent = leader
		
	local rxp = Instance.new("IntValue")
	rxp.Name = "ReqEXP"
	rxp.Parent = leader
	
	local pfaction = Instance.new("StringValue")
	pfaction.Name = "Faction"
	pfaction.Parent = leader
	
	
	-- When XP Changes check for Level up --
	xp.Changed:Connect(function() 
		print("EXP Changed")
	end)
	
end)

All I’m trying to do for the time being is to recognize the change so I can edit it at a later time. However when I change the experience after pressing play in the studio nothing happens. Any help would be much appreciated!

I’m guessing you changed it in Client-Mode. If that’s the case, the server won’t recognize or read the changes to the value, as client changes do not replicate to the server.

You can click on the button in the left upper corner of your Studio test window to toggle to Server-Mode.

:slight_smile:

1 Like

Thank you so very much! This is exactly what I was doing wrong. I assume that if I wanted to allow a GUI to edit the experience I would need to use remote events?

1 Like

If you just need the GUI to read the value of their experience, then you don’t need remotes. Otherwise, you’d want to use them to assure the change replicates server-sided as well.

:slight_smile:

1 Like