Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My gun shells don't get created in my script for some reason! How can I fix that?

local lastFired = tick()
game:GetService("RunService").RenderStepped:Connect(function()
	if firing then
		if tick() - lastFired > fireDelay then
			gunShoot:FireServer(m.Hit.p, muzzle.CFrame.p)
			lastFired = tick()
		end
		if tick() - lastFired > 0.3 then
			local GunShellClone = gunshell:Clone()
			GunShellClone.Parent = game:GetService("Workspace")
			GunShellClone.CFrame = muzzle.CFrame + Vector3.new(0, 0, 0)
			GunShellClone.Velocity = -(muzzle.CFrame.RightVector) * 10
			GunShellClone.CFrame = GunShellClone.CFrame * CFrame.Angles(math.random(0.3, 1), math.random(0.3, 1), math.random(0.3, 1))
			local GunShellClone_sound = gunshell_sound:Clone()
			GunShellClone_sound.Parent = muzzle
			GunShellClone_sound:Play()
			wait(5)
			GunShellClone:Destroy()
		end
	end
end)

So I wrote some code to make a full auto rifle full auto as well as a script for shell ejection. When I checked, the shells do get cloned, but for some reason in this instance they don't appear at all cause of the full auto thing not working out for the shells. First try they appeared first before the bullets and bullets only appeared after (the code was a bit different), second time they appeared once and stop appearing (also different code), and now they don't appear at all! I just need to get the ejected shells to appear at a slower rate as well as some camera shake at a slower rate from the full auto fire rate which is 0.1. Please help me.

4 comments

0

You will get a lot of GunShellClone_sound since you never destroy it

0

Wait are you saying that fireDelay is equal to 0.1? Then your if tick() - lastFired > 0.3 will never run. Since every time tick() - lastFired > 0.1 you reset lastFired, it will never get greater than 0.3

0

I see, perhaps there's a way I can fix that? What would it look like?

0

Okay, so I got it by making a seperate lastFired-like variable. Thank you.

1 answer

Okay, thanks to Spjureeedd, I got it. I finally understood that I had to make a seperate variable which would be like lastFired, but for the shells. Thank you dude, I can't upvote your post but I surely would If I could.

1 comment

0

No problem, just glad I can help

This discussion is preserved as it was. New answers, comments, and votes are closed.