Number Value Problem

I have a problem with the value, i did a script basic script in ServerScriptStorage, not problem with it, every 10 seconds it goes down 1
5-100
100% Is the normal value but when i walk on a certain part it decrease by 10, example:
5-79
normal and all, same value in the player child but after 10 seconds (not forced drop) it goes BACK to the basic value but with less number, so as it should be if there was not part touch
5-97
so could someone help me ? I will send the GUI script and “normal” script if someone ask.

Can you send the script?
And is the player only supposed to see his own sanity or see others too?

Sanityservice5
In ServerSeviceStorage and


This is in StaterGui in Sanity(GUI)

Btw only the own player can see it .

Just didnt understood the after 10 seconds thing.can you explain again for shortly?(Or long if you want)

The problem arises because you are updating the value from the client. When you decrease the value from the client, it doesn’t update on the server. So, every second the server decreases the server-side value, but each time the player interacts (touches the part) with it, the value decreases by 10 on the client side, resulting in no update.

Cant believe i forgot that.client is only visible to player.server cant see it.

1 Like

in the first screenshot of my second message you can see local DECREASE_FREQUENCY = 5 (its not 10 seconds anymore but 5) , it mean that every 5 seconds i lost 1 amount of the value

do you have any idea on how to fix it ?

Using server to detect and get the character that touched by player is the best option.

Just do the sanity loss on the client as well

On both script or i just move it to the client ?

you move the server script code into the client, preferably in the same localscript as in the second screenshot you sent

i used the script of serverscriptservice to create the value inside the player , but now the value isn’t created anymore, maybe i can easily fix it

do you necassarily need an intvalue for the sanity? cause you can just do:

local sanity = 100

smth like that and just do the same strat with the while loop you did

Then how the client will access? Remote event sounds bad to me.

but how do i create the value in the player then ? I can’t figure out.

what do you mean ? No one brought remote event

nvm just use attributes

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local gui = player.PlayerGui.Sanity.Bar
local part = workspace:WaitForChild("CoolPart3")

local WaitTime = 5
local DecreaseSanity = 1

player:SetAttribute("Sanity", 100)

gui.Percentage.Text = "Sanity: 100%"

part.Touched:Connect(function(hit)
	if hit.Parent == character then
		player:SetAttribute("Sanity", player:GetAttribute("Sanity") - 10)
	end
end)

player:GetAttributeChangedSignal("Sanity"):Connect(function()
	gui.Percentage.Text = "Sanity: "..player:GetAttribute("Sanity").."%"
end)

while task.wait(WaitTime) do
	if player:GetAttribute("Sanity") <= 0 then
		-- yea you have to send a remote for this one (in order to kick the person)
	else
		player:SetAttribute("Sanity", player:GetAttribute("Sanity") - DecreaseSanity)
	end
end


What does it mean, im pretty new at scripting so idk what does it mean. Also, how do i set up the remote event ?

ive changed the script a bit, should be ok now

also if errors send what code line it is :+1: