Script Not Updating Value

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I’m Trying To Make Some Stats For My Game But All Just Randomly Broke

  2. What is the issue? The Remote Event From Client Sends The Stats And Value To Server So The Server Can Update The Stats

  3. What solutions have you tried so far? I’ve Tried Looking On Devforum But Didn’t Find Anything

The Server Script Should Update The Values And Another Local Script Should Display Them On Gui, But Only The Health Works Properly

  1. Script That Send Data To Server
local Players = game:GetService("Players")
local rs = game:GetService("ReplicatedStorage")

local localPlayer = Players.LocalPlayer
local updateEvent = rs.Events:WaitForChild("UpdateValues")
local Humanoid = Players.LocalPlayer.Character:WaitForChild("Humanoid")

while task.wait(script:WaitForChild("HungerDelay").Value) do
	warn("Hunger")
	updateEvent:FireServer("Hunger", "PlayerStats", 1, "-")
end
  1. Script That Changes The Values
local UpdateValues = game.ReplicatedStorage.Events:WaitForChild("UpdateValues")

UpdateValues.OnServerEvent:Connect(function(plr, value, stat, amount, arith)
	if value and stat and amount and arith then
		local TrueStat = plr:FindFirstChild(stat)

		if not TrueStat then
			warn("Stat Not Found")
			return
		end

		local TrueValue = TrueStat:FindFirstChild(value)

		if not TrueValue then
			warn("Value Not Found")
			return
		end

		if arith == "+" then
			TrueValue.Value = TrueValue.Value + amount
		elseif arith == "-" then
			TrueValue.Value = TrueValue.Value - amount
		elseif arith == "*" then
			TrueValue.Value = TrueValue.Value * amount
		elseif arith == "/" then
			TrueValue.Value = TrueValue.Value / amount
		elseif arith == "toggle" then
			if TrueValue:IsA("BoolValue") then
				TrueValue.Value = not TrueValue.Value
			else
				warn("Invalid Arith for Value Type")
			end
		elseif arith == "set" then
			if TrueValue:IsA("StringValue") then
				TrueValue.Value = amount
			else
				warn("Invalid Arith for Value Type")
			end
		else
			warn("Invalid Arith")
		end
	else
		warn("Values Are Missing")
	end
end)

  1. Script That Puts The Values On Gui
wait(1)
local Players = game.Players
local localPlayer = Players.LocalPlayer
local Hunger = localPlayer:WaitForChild("PlayerStats"):WaitForChild("Hunger")
local Thirst = localPlayer:WaitForChild("PlayerStats"):WaitForChild("Thirst")
local Energy = localPlayer:WaitForChild("PlayerStats"):WaitForChild("Energy")
local Radiation = localPlayer:WaitForChild("PlayerStats"):WaitForChild("Radiation")
local HealthBar = script.Parent.Health
local HNumber = HealthBar.Number
local HBar = HealthBar.Bar
local HungerBar = script.Parent.Hunger
local ThirstBar = script.Parent.Thirst
local EnergyBar = script.Parent.Energy
local RadiationBar = script.Parent.Radiation

local Humanoid = localPlayer.Character:FindFirstChildOfClass("Humanoid")

local function getValues(value, BarParent, Bar, Text)
	local parentSize = BarParent.AbsoluteSize.x
	local cappedValue = math.clamp(value.Value, 0, 100) -- Clamp the value between 0 and 100

	-- Update the value in the stat itself
	value.Value = cappedValue

	Text.Text = cappedValue .. "%"
	Bar:TweenSize(UDim2.new(0, (cappedValue / 100 * parentSize), 1, 0), 'Out', 'Linear', '0')
end

local function getHealth(Humanoid, BarParent, Bar, Text)
	local parentSize = BarParent.AbsoluteSize.x
	local cappedValue = math.min(Humanoid.Health, 100) -- Cap the value at 100

	-- Update the value in the stat itself
	Humanoid.Health = cappedValue

	Text.Text = cappedValue .. "%"
	Bar:TweenSize(UDim2.new(0, (cappedValue / 100 * parentSize), 1, 0), 'Out', 'Linear', '0')
end

getHealth(Humanoid, HealthBar, HBar, HNumber)

Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
	getHealth(Humanoid, HealthBar, HBar, HNumber)
end)

getValues(Hunger, HungerBar, HungerBar.Bar, HungerBar.Number)

Hunger:GetPropertyChangedSignal("Value"):Connect(function()
	getValues(Hunger, HungerBar, HungerBar.Bar, HungerBar.Number)
end)

getValues(Thirst, ThirstBar, ThirstBar.Bar, ThirstBar.Number)

Thirst:GetPropertyChangedSignal("Value"):Connect(function()
	getValues(Thirst, ThirstBar, ThirstBar.Bar, ThirstBar.Number)
end)

getValues(Energy, EnergyBar, EnergyBar.Bar, EnergyBar.Number)

Energy:GetPropertyChangedSignal("Value"):Connect(function()
	getValues(Energy, EnergyBar, EnergyBar.Bar, EnergyBar.Number)
end)

getValues(Radiation, RadiationBar, RadiationBar.Bar, RadiationBar.Number)

Radiation:GetPropertyChangedSignal("Value"):Connect(function()
	getValues(Radiation, RadiationBar, RadiationBar.Bar, RadiationBar.Number)
end)

I Also Have Tools That Increase The Values

local Players = game:GetService("Players")
local rs = game:GetService("ReplicatedStorage")
local Eat = rs.Sounds:WaitForChild("Eat")

local updateEvent = rs.Events:WaitForChild("UpdateValues")

local Tool = script.Parent
local Food = Tool:WaitForChild("Food")
local PlayAnim = Tool:WaitForChild("PlayAnim")

local isEating = false

Tool.Activated:Connect(function()
	if isEating == false then
		isEating = true
		PlayAnim:FireServer("eat", "start")
		Eat:Play()
		wait(1.2)
		updateEvent:FireServer("Hunger", "PlayerStats", Food.Value, "+")
		PlayAnim:FireServer("eat", "end")
		Tool:Destroy()
	end
end)

Any Help Will Be Appreciated!

Could you please say if you’re getting any errors in the console?

I Tried Looking Everywhere But I Still Don’t See Any Errors

Debug the script to check what parts of it are running. I usually start by putting breakpoints at the beginning of the events. For example place one at the line after:

UpdateValues.OnServerEvent:Connect(function(plr, value, stat, amount, arith)

I Tried, All Of The Prints Work But The Value Refuses To Change

Is there a way to contact you so I can see it live on screen share cause all seems correct by the code written?

Im Sorry I Can’t Call Or Contact

One thing to ask. Which part works? Does the Client Updating not work, the tool’s increasing or what part?

the client does send the remote Event, probably has to do with the script that updates the values or the values themself

Do you get any updated value results?

i don’t get any, the values remain at 100

local UpdateValues = game.ReplicatedStorage.Events:WaitForChild("UpdateValues")

UpdateValues.OnServerEvent:Connect(function(plr, value, stat, amount, arith)
	if value and stat and amount and arith then
		local TrueValue = plr:FindFirstChild(stat):FindFirstChild(value)
		if not TrueValue then
			warn("Value Not Found")
			return
		end

		if arith == "+" then
			TrueValue.Value = TrueValue.Value + amount
		elseif arith == "-" then
			TrueValue.Value = TrueValue.Value - amount
		elseif arith == "*" then
			TrueValue.Value = TrueValue.Value * amount
		elseif arith == "/" then
			TrueValue.Value = TrueValue.Value / amount
		elseif arith == "toggle" then
			if TrueValue:IsA("BoolValue") then
				TrueValue.Value = not TrueValue.Value
			else
				warn("Invalid Arith for Value Type")
			end
		elseif arith == "set" then
			if TrueValue:IsA("StringValue") then
				TrueValue.Value = amount
			else
				warn("Invalid Arith for Value Type")
			end
		else
			warn("Invalid Arith")
		end
	else
		warn("Values Are Missing")
	end
end)

Could you test this in your code and tell me if you are getting any error in the console?

I Tried The Scripts, I’m Not Getting Any Errors

Could you try printing all the values before the if arith statements just to check that you are getting the requested variables and the OnServerEvent has been called? Just do

print(plr.Name .. " has sent an event request.")

he’s 100% not using chat gpt XD , just imagine

I mean it’s not me who I will be judging however I am not sure why it wouldn’t work for him.

isn’t it pretty obvious? he’s using a fireevent to the server with some informations but the server don’t even use the same informations that the client has send

I am not getting what you mean. Could you please elaborate?

just check he’s script correctly without using chat gpt you will get what i mean

Even if it’s chatgpted or not I recompiled it like many times and it worked for me. I can’t understand what would be the issue in that case.