How can this method be achieved with more optimization?

Hey all! Let me explain.

So I am making a system where if you shine a flashlight (not a tool, a literal built-in flashlight) at a doorway and if a monster is there, the monster will back off after the light was shined at them for x amount of time.

Since the flashlight functions (toggling on and off) are client-side (they are in StarterPlayerScripts) and the monster AI is server-side, I ended up creating a value in ReplicatedStorage that increases every frame the flashlight is on. When the monster appears, it’s reset to 0 and then it constantly checks if the value is higher than a specific constant.

However, since the increasing incorporates the delta via RunService (I wanted to eliminate framerate differences), my only “solution” so far was to send a RemoteEvent every frame the light is on, passing the delta as a parameter. Sadly, I think this is extremely unoptimized, and probably a bad idea to do. Can anyone recommend some better alternatives to somehow make the delta time available to the server?

2 Likes

Tell the server when you start looking at the monster and increase the value on the server and when you look away just tell the server to stop counting

1 Like

The issue is that I can’t seem to get the delta itself for the increase function (as far as I know RunService doesn’t give you the delta in server scripts)

2 Likes

RunService.Heartbeat gives you the delta on the server (it’s actually the only runservice event you can use on the server)

2 Likes

Thanks for your help!

c h a r a c t e r s

1 Like