Roblox Studio and Experience runtime are different

Pistol must shot with cooldown in 0.05s but in roblox client feels like this takes 1~3s reload
The task.wait()s and not only are seems taking more longer in roblox player than in studio and im really, REALLY confused why this happens, just like im not using outdated wait() and using his task variation but that not seems very helping, i can show it must look and how it looks in roblox player.

1 Like

is this delay in a while loop?

script looks like

local t = script.Parent
t.Activated:Connect(function()
if not cooldown then

cooldowned = true

-- it play animation
-- it play sound

-- deals damage etc

task.wait(0.05)

cooldowned = false

else

end
end)

I think of making if cooldown (which is a boolean: true) then return end (it’s not neccessary add to else unless something)

does it change ?

the issue is not in cooldown, please read whole post again and then return here

The issue may be server/client latency

Also the thing i mentioned that the my script will do nothing if object (rifle tool example) didnt found but if object parent has humanoid will damage it but thats not the topic, the problem is if there is no object it shoots enough fast but IF THERE object it takes some more time but im delete any Client connections (Remotes) to cut execution time and this how it appears.


Its REALLY serious trouble and i wanna solve it to not ruin my gameplay

I’m not trying to be this but

We need information, what it is code (at least of Methods it uses)

What methods, events, connections it uses

We can’t help you due to not knowing what causes that. :confused:

Because you disabled ping simulation and wrote awful code that does not even know what network delay is.

Because in Roblox Studio your ping will always be 0ms since the server is simulated locally on your device

abt that my avg ping is ~130-160ms not that critical for this kind of delay

Help❌
Became toxic say youre made awful code and this is you bad dev lolâś…

2 Likes

A possible could fix could be to use os.clock for the cooldown instead of task.wait
To set it up:

  1. Make a “lastUse” variable with its starting value set to zero.
  2. Make a “COOLDOWN_TIME” variable with its value set to what you need.
  3. When the player tries to use the tool, do this check: (os.clock() - lastUse) > COOLDOWN_TIME
  • If it returns true, the player is out of cooldown and can use the tool again. If not, don’t activate the tool
  1. When the player uses the tool succesfully, update the “lastUse” variable: lastUse = os.clock()

People see what they want to see.
You inherently interpreting my response as “toxic” could be your projection.
Also, I had a stroke reading your reply.
If I were to say something else, that would mean that I would lie, which I don’t want to do.

Here is full rifle code like just from Rifle.Script

local t = script.Parent
local c = nil
local p = nil
local h = nil

local usrs = game.Players

local animations = {}

local rs = game["Run Service"]

local e = false

local eqanim = false

local reload = false

t.Equipped:Connect(function()
	e = true
	if not c then
		c = t.Parent
		p = usrs:GetPlayerFromCharacter(c)
		h = c:FindFirstChildWhichIsA('Humanoid')
		
		animations = {
			hold = h:LoadAnimation(script.Hold),
			walk = h:LoadAnimation(script.Walk),
			shot = h:LoadAnimation(script.Shot),
			reload = h:LoadAnimation(script.Reload),
			equip = h:LoadAnimation(script.Equip)
		}
	end
	
	animations.equip:Play()
	
	eqanim = true
	
	task.wait(0.25)
	
	if e then
		animations.hold:Play(0.25)
		
		t.Handle.Equip:Play()
	end
	
	task.wait(0.95-0.25)
	
	eqanim = false
end)

t.Unequipped:Connect(function()
	e = false
	animations.hold:Stop(0.25)
end)

rs.Heartbeat:Connect(function()
	if h then
		local mvd = h.MoveDirection
		local magn = mvd.Magnitude
		
		if magn > 0.2 then
			if e then
				if not animations.walk.IsPlaying then
					animations.walk:Play(0.2)
				end
			else
				
			end
		else
			if animations.walk.IsPlaying then
				animations.walk:Stop(0.2)
			end
		end
		
		animations.walk:AdjustSpeed(magn/1)
	else
		
	end
end)

local cooldowned = false

local function reloadPistol()
	if not reload and not cooldowned then
		if t.Ammo.Value < 30 then
			cooldowned = true
			if e then
				animations.reload:Play()
			end
			task.wait(0.25)
			if e then
				t.Handle.MagOut:Play()
			end
			task.wait(0.5)
			if e then
				t.Handle.MagIn:Play()
				t.Ammo.Value = 30
			end
			task.wait(0.25)
			if e then
				t.Handle.ChargeRel:Play()
			end
			task.wait(0.5)
			cooldowned = false
		else
			
		end
	else
		
	end
end

local function shot()
	if not cooldowned and t.Ammo.Value >0 and not eqanim then

		animations.shot:Play()
		local s = t.Handle.Fire:Clone()
		s.Parent = t.Handle
		s.PlayOnRemove = true
		s:Destroy()

		cooldowned = true

		t.Ammo.Value -= 1

		local object,hitpoint = script.requestHitpoint:InvokeClient(p)

		t.Handle.PointLight.Enabled = true
		task.wait(0.02)
		t.Handle.PointLight.Enabled = false

		if object then
			local obj_c = object.Parent

			local obj_h = obj_c:FindFirstChildWhichIsA("Humanoid")

			if obj_h then
				if object.Name == 'Head' then
					obj_h:TakeDamage(13.33)
				else
					obj_h:TakeDamage(3.33)
				end

				task.wait(0.1)

				if obj_h.Health <= 0 then
					local a = game.ReplicatedStorage["KO Bonus"]:Clone()
					p.KOs.Value += 1
					p.Killstreak.Value += 1
					a.Parent = p.PlayerGui.HUD
					game.Debris:AddItem(a, 1)
					p.Cash.Value += 1
				else

				end
			else

			end
		end

		task.wait(0.05)

		cooldowned = false

	else
		if t.Ammo.Value <= 0 then
			t.Handle.Empty:Play()
			reloadPistol()
		end
	end
end

script.reload.OnServerInvoke = reloadPistol

local active = false

t.Activated:Connect(function()
	active = true
end)

t.Deactivated:Connect(function()
	active = false
end)

local lastShot = os.clock()

local rs = game["Run Service"]

rs.Heartbeat:Connect(function()
	
	
	
	if active and (os.clock() - lastShot)>0.1 then
		shot()
	else
		
	end
end)

In your shoot function, you have a task.wait()'s already which adds onto the time it takes for it to go off cooldown:

This is the only problem I could really think of for the cooldown being longer, you can either use task.delay at the top to automatically put it off cooldown without the script influencing it or wrap some of the code that waits in task.spawn.

This is also especially true since you have a wait after hitting a player, if you remove that it should work fine?

I don’t think you need to use heartbeat (it’s before the replication, not the Roblox pre-caclution)

Task.wait is being used…

You need add the activate to activated

Loop delay (of heartbeat) is issue (someone low device can perhaps has issues with gameplay on that code line)