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”.