Time and which type to use. . (RunService / Wait() / Tick())

All right, so I’m having some problems with inconsistent timing on the server and client. I want to be able to simultaneously drain something like Stamina or Health from the client and the server simultaneously. There’s obviously a delay with things like ping, and that’s fine with me, for me it’s really about the amount of time a function runs.

For example, I have a function to drain Stamina or Health from the client and the server after a remote has been fired, but they always end up out of sync. The values for Stamina aren’t the same on the client, as they are on the server after a certain period of time spent toying around with the drain.

Now, I’m guessing this is an issue with timing being out of sync, the server’s ‘stamina regen’ not syncing with the client’s, and ending at abrupt times, I can only guess because of differences in ping, or framerate

Now, I’ve tried to use Runservice.Heartbeat and Wait() to try to solve this issue, but they don’t seem to work, how could I fix something like this?

What form of time should I use so the client and server are as synced as they can possibly be?

I would appreciate any help! :sweat_smile: :pray:

I have a function to drain Stamina or Health from the client and the server after a remote has been fired, but they always end up out of sync. The values for Stamina aren’t the same on the client, as they are on the server after a certain period of time spent toying around with the drain.

how your script is ACTUALLY made? are you using a remote event just to change
health or some stats?

just asking

I could post it, but it would be a lot of modules and stuff

Basically, I have a local-version of my stats like Stamina and Health, and then I have a server-side version, I need them to operate independently so that the player can get that instant gratification from draining stamina and stuff, and can operate on the same cooldowns that the server has in place

I have a Local Data, and a Server Data (Data on the Local that the Server updates through remotes every now and then, but is mostly updated by the client itself, and Data on the Server, which the client cant access at all, and is updated by the server)

So, whenever you update the value in [Server-side script] you send a remote event to
the client? and then update it right,

i have a system where i don’t use remote events,
btw, the Server really has some delay,
i experienced this while testing stats and stuff doing
Server > client
client > server just to update some value

-- for example

local E = Instance.new("NumberValue", player)
E.Name = "Experience"
E.Value = 0

--Server Script
player.Experience:GetPropertyChangedSignal("Value"):Connect(function(NewExp)

     --something will run here when experience changes

end)

–since that was an Instance, i don’t have to send anything via remote

--Local Script
--No remote no problem

--I normally create a  

RemoteEventName.OnServerEvent. here to prevent some errors

So when the server start, FIRST i wait the Server to load all data then
in the end of the Script it will run a Remote event (from the server, to the client) warning that the server finished
and this Local Script will run safe ( no errors ) (infinite yield of smthng like that)



local plr = game.Players.LocalPlayer
local PlayerGui = plr:WaitForChild("PlayerGui") -- Gui's only

local Experience = plr:WaitForChild("Experience") 

Experience:GetPropertyChangedSignal("Value"):Connect(function()
--Since the Experience changed Server-Side, the client will automatically update

--if you want a fast response, that would be a good way i believe

playerGui:WaitForChild("YourGui").TextLabel.Text = Experience.Value

--This can be anything, it will update fast,

-- [ i don't know about delay, haven't experienced this before]

end)


anyway, correct me if i said something wrong, i’m here to learn in the end
but this works

1 Like

Task.wait with a debounce works well.

Basically, the server has that delay, like you said, so I have the Client and Server operating completely independently, occasionally the server is the one editing stuff in things that the client wouldn’t otherwise pick up, like ‘You’ve been hit!’, but those things will have that delay regardless since it has to pass through the client-server boundary.

I don’t use Instances because I want to get good with modules since so far they’ve made management really easy for me, but I may have to switch back to Instances

Think of it like this.

(Player punches.)

Client | Personally updates their own data, so while the player is punching, they can’t fire the dashing remote and don’t bug out their script.

Server | When the server receives the data, they update the server-side version of the stats, so that it can Actually have an effect that isn’t only visible for the client

My issue is with getting these two to work together flawlessly, like even if one is 1 second behind, it’ll only for example ‘DRAIN 15 Stamina’ total, from the client or server, regardless of the delay

I will be trying this! :+1:

What do you mean by a ‘debounce’ though? Like I know what it is, but how would that help with the timing?

its used to make cooldowns, heres a tutorial Debounce Patterns | Roblox Creator Documentation