IntValue only sets at 0

  1. What do you want to achieve? Keep it simple and clear!
    I’m making LocalPlayer script that turns a player’s saved checkpoints green when a they join the game.
  2. What is the issue? Include screenshots / videos if possible!
    In the leaderstats, it is shown that the checkpoint value of a player is 10, for example. But in the Output it is only printed out as 0.

This is the script:

local CheckPoints = game.Workspace:WaitForChild("CheckPoints")

local Plr = game.Players.LocalPlayer
local leaderstats = Plr:WaitForChild("leaderstats")
local checkpoint = leaderstats:WaitForChild("Checkpoint",10)


local function SavedCheckPointsColor()
	print("GRN")
	for _,thing in CheckPoints:GetChildren() do
		--check if thing is a checkpoint
		local areaNum = tonumber(string.match(thing.Name, "[0-9]+$"))
		if thing.Name:find("CheckPoint") and areaNum and areaNum > 0 then

			if areaNum <= checkpoint.Value then
				print(tostring(thing))
				if thing:FindFirstChild("Point") then
					local Point = thing:FindFirstChild("Point")
					print(Point.Parent)
					----point GREEN
					Point.BrickColor = BrickColor.new("Lime green")
				else 
					warn("no POINT?")
				end
			else
				print(areaNum..">"..checkpoint.Value)
			end

		end

	end

end

while not game:IsLoaded() do
	task.wait()
end
SavedCheckPointsColor()
	
1 Like

I believe this issue happens because it’s a LocalScript. When you change a value on the client, it does not affect the server, which causes a mismatch. This is why the script prints 0, but in leaderstats, it might show 7 on the client. To fix this, you could use a RemoteEvent to send the client value to the server, ensuring both are in sync.

1 Like

The value was changed by a server script, when I switched to Server side to read the value, it was still 10

I temporarily fixed the script

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.