Stat changing on the server but not the client

I want to make a system, so that if the players stamina is more than their Max Stamina, it will fire the server and the server will change the Stamina to the Max Stamina

The Stat changes on the server with no issues, however on the client it doesn’t change.

This is what it looks like on the client (it’s inside a local script that changes a UI)

while wait() do
	script.Parent.Size = UDim2.new(Player.PlayerStats.Stamina.Value / Player.PlayerStats.MaxStamina.Value, 0, 1, 0)
	script.Parent.Parent.HealthText.Text = math.round(Player.PlayerStats.Stamina.Value, 1).."/"..Player.PlayerStats.MaxStamina.Value
	
       -- letting the server know about it
	if game.Players.LocalPlayer.PlayerStats.Stamina.Value > Player.PlayerStats.MaxStamina.Value then
		game.ReplicatedStorage.Events.StaminaMoreThanMax:FireServer()
	end
end

This is what it looks like in the server

replicatedStorage.Events.StaminaMoreThanMax.OnServerEvent:Connect(function(player)
	print("I have the message")
	player.PlayerStats.Stamina.Value = player.PlayerStats.MaxStamina.Value -- setting stamina to the max stamina
	if player.PlayerStats.Stamina.Value == player.PlayerStats.MaxStamina.Value then
		print("I have changed it")  -- debugging
	end
end)

When playtesting and switching between the client and server, the clients stamina wont change, but on the server the players stamina changes. It’s also worth noting that due to the while wait() do loop, it’s constantly firing the server, meaning that the server is always printing out “I have changed it”.

1 Like

show us what does it actually print

1 Like

This is the server constantly printing as its constantly getting the message, and the UI shows that its not changing on the client.

image

1 Like

Now check your stamina value, if its 100 you should fix your healthtext script

1 Like

On the client it’s saying it’s 101, even in the properties tab, then when I switch to the server its saying its 100.

1 Like

make it so it checks on client and not on server, or else exploiter will abuse it + it will help you fix your problem easily

But am I able to change the stat on the client without it only being changed on the client?

You shouldn’t need to fire the server to do something like that.

Use math.clamp. Wherever you’re changing the Stamina value, use math.clamp(newStaminaValue, 0, maxStaminaValue).

Thanks, I thought that I wouldnt be able to do it on the client because I thought it would only change on the client.

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