#inconsistent waiting times in a while true do loop
24 messages · Page 1 of 1 (latest)
ahh alright then
just use runservice and replace while with if
about the randomizeattacks, you can use a coroutine that restarts itself after completed, even if maybe it isn't the best way, and no, it shouldn't be inside runservice but before or after it
** You are now Level 3! **
didnt ask
show example
i have no idea how to visualize that
and also whats wrong loops, ehat they do
alright so. each client runs at a set framerate, lets say you have a good pc so you do 80 fps but i have a crappy pc and do 20 fps, if you use a while loop, that's considered "wrong" loops, all those: while true do, while wait() do, while task.wait() do, ALL those, no matter what, i think the only exception is while wait(RunService.Step) do but im not sure at all if thats even called step, but basically should some float time which is 1/YOUR FPS, so if you do 80 fps its gonna be 0.0125, i do 20 fps its gonna be 0.05.
lets do another example, a cube moving horizontally, you would see it smooth because it updates 80 times per second, so lets say it reaches the end in 4 seconds, me too, will see it end in 4 seconds, and it will move faster to me, because there are less frames to update, so yeah your cube will visually be slower than mine, if it were the same speed, yours would finish in approximately 4 seconds and mine.. well 20, 40, 60, 80.. about x4 more time
those bad loops exactly do that, executes stuff at a set time for everyone which is bad.
So there is a simple and optimized solution.
RunService.RenderStepped(function(deltaTime)
-- ur looping code here
end)
to make it stop, you can use a simple programming rule, you can convert whiles to ifs and viceversa, same with repeating and other similar, because each of these is made out of a condition, so just make a boolean and..
local canAttack = true
local db = true -- debounce
local db2 = true
RunService.RenderStepped:Connect(function()
if not canAttack then return end
if db then
db = false
-- loop stuff
RandomizeAttacks()
task.wait(1)
db = true
end
if not targetplayer.Value and db2 then
db2 = false
print("fard")
task.wait(1)
db2 = true
end
end)
note that i wrote this from a phone so sorry for grammatical errors and stuff, english isnt my primary langauge
local canAttack = true
local db = true -- debounce
RunService.RenderStepped:Connect(function()
if not canAttack then return end
if db then
db = false
-- loop stuff
RandomizeAttacks()
if not targetplayer.Value then
print("fard")
end
task.wait(1)
db = true
end
end)
edit coz discord sucks: this one code is even better because uses only one debounce
isnt RenderStepped only for client
cuz im making a boss fight, that operates on server
and probably SHOULD run on server
i believe so, but you can use .Heartbeat instead, it's basically the same thing but updates AFTER the physics, there aren't really more workarounds, but otherwise you can fire all the clients from the server and update the boss fight stuff
gl w ur game
ill try this out, thanks for the info!
np