Wait time doesn't works, even when its more than 1/30?

For some reason, I am making an auto script gun, and there should be no errors, but the gun cadence, isn’t the correct, even when cadence is set to 0.

 repeat
			if Equipped and (tick() - lastshot)  >= Tool.Configurations.Cadence.Value then
		lastshot = tick()
			Shot()
		end
			wait()
		
		until shooting == false or Tool.Configurations.Ammo.Value < 1

This is the part of Automatic shot, but I still can’t understand what’s the error, this is how the gun cadence shots: https://gyazo.com/30fcddbc536b2753c615124f61d1a532
As you can see in video, this is clearly not 0.001, the correct cadence, it’ll shoots fast, but, I don’t think that’s 0.001

This is the Cadence Value: 0.0010000000000000000208

Even when changing to LESS or 0 it doesn’t affects.

To see how much time has actually elapsed, you could print out what wait() returns.

It might be a better option to go for more of a timer-based wait system, avoiding the use of wait(), which can be unreliable.

Generally, something like this may work better for your case-

local function Yield(secs)
local t = tick()
while tick() - t < secs do
game["Run Service"].Stepped:Wait()
end
end

Although, I do wonder if the delay you’re seeing is client-to-server replication?? Not really sure how you set up your gun system.

1 Like

Hey so, I changed thewait for RunService.renderstepped:wait() still, doesn’t shots correctly, I mean, I don’t think it’s the wait, do you know something that might cause this? :thinking:

Edit:
I removed the Tick() stuff, but, it still shots iwht that cadence, so I suppose it’s something else, but I don’t know why

Could you post more of your gun code??

Yes, apologies for late response,

Mouse.Button1Down:Connect(function()
	
	if canshot then
	if Equipped then
	if Tool.Configurations.Ammo.Value > 0 then
		shooting = true
	if Tool.Configurations.Auto.Value == true then
	
   repeat
			if Equipped and (tick() - lastshot)  >= Tool.Configurations.Cadence.Value then
		lastshot = tick()
			Shot()
		end
			game:GetService('RunService').RenderStepped:Wait()
		
		until shooting == false or Tool.Configurations.Ammo.Value < 1
		
			elseif Tool.Configurations.Auto.Value == false and (tick() - lastclick) > Tool.Configurations.Cadence.Value then
				lastclick = tick()
				Shot()
				end
		end
		end
		end
end)
Mouse.Button1Up:Connect(function()
	if Equipped or shooting then
		shooting = false
	end
end)

Well, incase you want the, shot function, kinda a mess but here you go:

local function  Shot()	
				Recoil()
							
		
				for i,v in ipairs(Tool.Body.FirePart:GetChildren()) do
					if v:IsA('ParticleEmitter') then
						v.Enabled = true
					end
				end
				if Tool.Configurations.ShotgunEnabled.Value == true then
							local Part = game.ReplicatedStorage.WeaponSystem.FX.ShotgunShell:Clone()
	Part.Velocity = Tool.Body.ShellEject.CFrame.LookVector.Unit * math.random(Tool.Configurations.ShellDropDistance.Value-10,Tool.Configurations.ShellDropDistance.Value) + Vector3.new(0,4,0)
	Part.Transparency = 0
	Part.Parent =  workspace.IgnoreParts
	Part.CFrame = Tool.Body.ShellEject.CFrame * CFrame.Angles(0,math.rad(90),0)
		game:GetService('Debris'):AddItem(Part, 4)
							elseif Tool.Configurations.ShotgunEnabled.Value == false then
				local Part = game.ReplicatedStorage.WeaponSystem.FX.Shell:Clone()
	Part.Velocity = Tool.Body.ShellEject.CFrame.LookVector.Unit * math.random(Tool.Configurations.ShellDropDistance.Value-10,Tool.Configurations.ShellDropDistance.Value) + Vector3.new(0,4,0)
	Part.Transparency = 0
	Part.Parent =  workspace.IgnoreParts
	Part.CFrame = Tool.Body.ShellEject.CFrame * CFrame.Angles(0,math.rad(90),0)
		game:GetService('Debris'):AddItem(Part, 4)
	end
				game.ReplicatedStorage.WeaponSystem.Events.Shot:FireServer(Tool)
				delay(0.1, function()
							for i,v in ipairs(Tool.Body.FirePart:GetChildren()) do
					if v:IsA('ParticleEmitter') then
						v.Enabled = false
				end
				end
				end)
					if Tool.Configurations.Ammo.Value < 1 then		
		game.ReplicatedStorage.WeaponSystem.Events.Bolt:FireServer(true,Tool)
		end
	---- LA RAY Y ESO XD
	if Tool.Configurations.ShotgunEnabled.Value == false then
	if Equipped and not Reloading and IsThirdPerson() then
 local ray = Ray.new(Tool.Body.FirePart.CFrame.p, (Mouse.hit.p - Tool.Body.FirePart.CFrame.p).unit * 5000 + Vector3.new(0,0.1,0))
local hit,position,surface = workspace:FindPartOnRayWithIgnoreList(ray, {Character, armmodel, workspace.IgnoreParts})

if hit and hit.Parent then
game.ReplicatedStorage.WeaponSystem.Events.Hit:FireServer(hit,position,surface, Tool,DamageModule[hit.Name])

if hit.Parent:FindFirstChild('Humanoid') then
	script["A hit"]:Play()
end
end
--[[if (not Aiming) and IsThirdPerson() then
StopAnimations()
PlayAnimation('Shot')
delay(0.2, function()
	StopAnimations()
	PlayAnimation('Hold')
end)
end	
end]]
end
	if Equipped and not Reloading and IsFirstPerson() then

 local ray = Ray.new(Tool.Body.FirePart.CFrame.Position, Tool.Body.FirePart.CFrame.LookVector.Unit * 5000)
local hit,position,surface = workspace:FindPartOnRayWithIgnoreList(ray, {Character, Camera, workspace.IgnoreParts})

if hit and hit.Parent then
game.ReplicatedStorage.WeaponSystem.Events.Hit:FireServer(hit,position,surface, Tool, DamageModule[hit.Name])
if hit.Parent:FindFirstChild('Humanoid') then
	script["A hit"]:Play()
end
end
	
	end
elseif Tool.Configurations.ShotgunEnabled.Value == true then

	if Equipped and not Reloading then
		for i = 1,5 do
			shotgunshot()
		end
		end		
end
end
1 Like

I think there’s no errors? I Mean, there’s no errors, but, there’s nothing else, like debounce or anything, I don’t know what’s causing it… :confused:

is there a limit for remote event firing?