Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
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.

0
You will get a lot of GunShellClone_sound since you never destroy it Spjureeedd 385 — 4y
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 Spjureeedd 385 — 4y
0
I see, perhaps there's a way I can fix that? What would it look like? MrDarkLord1234 7 — 4y
0
Okay, so I got it by making a seperate lastFired-like variable. Thank you. MrDarkLord1234 7 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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.

0
No problem, just glad I can help Spjureeedd 385 — 4y
Ad

Answer this question