Int-Values updating on Client side but not on the Server side

So let’s say we have a RemoteEvent in ReplicatedStorage called ‘DoUpdateStageValue’. (At least that’s what I think you’re trying to change.)

Remote:FireServer(...) is sent from the client. Think of it this way: It will tell the server, “Hey! I got a request for you. Please do something with the arguments I provided.”

Remote.OnServerEvent is an event that can be connected to. This will receive the Player and the arguments the Player sent.

We can put together something like this to change the value:
Server:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UpdateStageRemote = ReplicatedStorage.DoUpdateStageValue

UpdateStageRemote.OnServerEvent:Connect(function(Player, ToChange) -- Player is the player instance.
    Player.Stage.Value = ToChange -- Make sure to do integrity checks. It's important! This is just a demonstration so it's not needed.
end)

Client:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UpdateStageRemote = ReplicatedStorage.DoUpdateStageValue

UpdateStageRemote:FireServer(1) -- where 1 is the value to set the stat to
1 Like

The :FireServer() is on the local script, you can have them inside .MouseButton1Click events.

OnServerEvent is on a Script

It underlines the last end)

Previous.MouseButton1Click:Connect(function()
	previousLevel()
	removeEvent:FireServer("updateStage", 3)

	remoteEvent.OnServerEvent:Connect(function(plr, job, msg)
		if job == "updateStage" then
			plr.Stage.Value = msg
		elseif job == "updateSpawn" then
			plr.Spawn.Value = msg
		end
	end
end)

As per my last reply, onServerEvent must be on a Script, not on LocalScript.

About the error, there’s a missing ) on the 2nd last end

Thought you said to put it in the MouseButton1Click?

I said that the OnServerEvent must be in a script

Okay, I put it in a regular script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("remoteEvent")

remoteEvent.OnServerEvent:Connect(function(plr, job, msg)
	if job == "updateStage" then
		plr.Current.Value = msg
	elseif job == "updateSpawn" then
		plr.SpawnPoint.Value = msg
	end
end)

Is this correct? Now I have to put the FireServer() in the MouseButton1Click events correct?

Yes for both questions, keep in mind I didn’t check if plr.Current.Value is correct, you might have to change both of those

Alright, and what is msg? I just want to know so I know what they’ll be equal too.

When you FireServer you pass to arguments (this is not a rule, this is literally what you done up there), “updateStage” and 3.

On the OnServerEvent you receive 3 arguments, plr, job, msg. Plr is the argument roblox adds, which is the player who fired it. The other two are the arguments you name, the arguments you send on the FireServer. So if you sent “updateStage” and 3, job and msg will be “updateStage” and 3 correspondingly

1 Like

Here I’ll help better explain this:

remoteEvent.OnServerEvent:Connect(function(plr, job, msg)
	if job == "updateStage" then
		plr.Current.Value = msg
	elseif job == "updateSpawn" then
		plr.SpawnPoint.Value = msg
	end
end)

plr - the player
job - what you are wanting to update
msg - the new value

msg can be changed to anything like number, stagevalue, etc.

it’s essentially what is being said earlier. Remember, you can’t change values in a local script because the server can’t see it, only the client. That’s why you need this remote event.

1 Like

Just double checking, I put nothing in these parenthesis?

remoteEvent:FireServer()

If so, it did not work. :pensive:

You had it well here, you need to tell the server what to do, otherwise it has no idea

1 Like

You need the parameters, set the job name, and vslue

1 Like

I put this in each button click:

remoteEvent:FireServer("updateStage", 3)

It didn’t work.

1 Like

Are you firing this in a local script?

Yes I am, in each button click in this script:

local UI = script.Parent

local player = game.Players.LocalPlayer

local checkpoints = workspace:WaitForChild("Checkpoints")

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Teleport = ReplicatedStorage:WaitForChild("Teleport")
local remoteEvent = ReplicatedStorage:WaitForChild("remoteEvent")

local Counter = UI:WaitForChild("Counter")
local Level = Counter:WaitForChild("Level")
local Previous = UI:WaitForChild("Previous")
local Next = UI:WaitForChild("Next")
local Previous1 = UI:WaitForChild("Previous1")
local Next1 = UI:WaitForChild("Next1")
local CurrentValue = UI:WaitForChild("Current")

local function previousLevel()
	script.Parent.Handler.Click:Play()
	if CurrentValue.Value ~= 1 then
		CurrentValue.Value = CurrentValue.Value - 1
		player.hidden.SpawnPoint.Value = player.hidden.SpawnPoint.Value - 1
		print("Wait")
		Level.Text = CurrentValue.Value
		-- teleport
		Teleport:FireServer(checkpoints:FindFirstChild(tostring(CurrentValue.Value)))
	end
end

local function previousLevel2()
	script.Parent.Handler.Click:Play()
	if CurrentValue.Value >= 11 then
		CurrentValue.Value = CurrentValue.Value - 10
		player.hidden.SpawnPoint.Value = player.hidden.SpawnPoint.Value - 10
		Level.Text = CurrentValue.Value
		-- teleport
		Teleport:FireServer(checkpoints:FindFirstChild(tostring(CurrentValue.Value)))
	end
end

local function nextLevel()
	script.Parent.Handler.Click:Play()
	if (CurrentValue.Value + 1) <= player.leaderstats.Stage.Value then
		CurrentValue.Value = CurrentValue.Value + 1
		player.hidden.SpawnPoint.Value = player.hidden.SpawnPoint.Value + 1
		Level.Text = CurrentValue.Value
		-- teleport
		Teleport:FireServer(checkpoints:FindFirstChild(tostring(CurrentValue.Value)))
	end
end

local function nextLevel2()
	script.Parent.Handler.Click:Play()
	if (CurrentValue.Value + 10) <= player.leaderstats.Stage.Value then
		CurrentValue.Value = CurrentValue.Value + 10
		player.hidden.SpawnPoint.Value = player.hidden.SpawnPoint.Value + 10
		Level.Text = CurrentValue.Value
		-- teleport
		Teleport:FireServer(checkpoints:FindFirstChild(tostring(CurrentValue.Value)))
	end
end


Previous.MouseButton1Click:Connect(function()
	previousLevel()
	remoteEvent:FireServer("updateStage", 3)
end)

Previous1.MouseButton1Click:Connect(function()
	previousLevel2()
	remoteEvent:FireServer("updateStage", 3)
end)

Next.MouseButton1Click:Connect(function()
	nextLevel()
	remoteEvent:FireServer("updateStage", 3)
end)

Next1.MouseButton1Click:Connect(function()
	nextLevel2()
	remoteEvent:FireServer("updateStage", 3)
end)

CurrentValue.Value = player:WaitForChild("leaderstats").Stage.Value
Level.Text = CurrentValue.Value

player.leaderstats.Stage:GetPropertyChangedSignal("Value"):Connect(function()
	CurrentValue.Value = player.leaderstats.Stage.Value
	Level.Text = CurrentValue.Value
end)

Is the event received, where is it not printing?

The print statments in :FireServer() are printing, so It must be something wrong with the script maybe?

You can use a remote event to trigger the int value change on the server.