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

Gun not firing properly?

I'm programming a Gun, and It's not "firing", I'm only working on sounds, mechanics, and animations. Not the Actual Statistics, is there something I did wrong?, I feel as if it's something to do with the way I've formatted the if Statements counteracting any functionality for Logical reasons.

I've had a lot of problems with tool.Activated before, it never runs. Am I doing something wrong with that too?

Here's the Script

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character
local Revolver = Player:WaitForChild("Backpack"):WaitForChild("Revolver")
local Handle = Revolver:WaitForChild("Handle")
local GunSounds = {
	GunEquipped = Handle:FindFirstChild("GunEquipped");
	GunFired = Handle:FindFirstChild("GunFired");
	GunReloaded = Handle:FindFirstChild("GunReloaded")
};
local GunAnimations = {
	GunEquiping = Character:FindFirstChild("Humanoid"):LoadAnimation(Handle:FindFirstChild("GunEquip"));
	GunFiring = Character:FindFirstChild("Humanoid"):LoadAnimation(Handle:FindFirstChild("GunFire"));
	GunReloading = Character:FindFirstChild("Humanoid"):LoadAnimation(Handle:FindFirstChild("GunReload"));
};
local Bullets = 1
local Fired = nil
local Reloading = nil
local Equipped = nil
local Unequipped = nil
local PlayerDirect = Revolver.Parent.Parent

Revolver.Equipped:Connect(function(Cursor)
	if Revolver and Equipped then return end
	Equipped = true
	if Revolver and Player then
		spawn(function()
			GunSounds.GunEquipped:Play()
		end)
		if Character:FindFirstChild("Humanoid") then
			GunAnimations.GunEquiping:Play()
		end
	end;
	Unequipped = false
end)

Revolver.Activated:Conenct(function()
	if Revolver and not Reloading then return end
	Fired = true
	print("GunFired")
	if Revolver and Player then
		spawn(function()
			GunSounds.GunFired:Play()
		end)
		Bullets = Bullets - 1
		if Bullets < 1 then
			Reloading = true
		end;
		if Reloading then
			spawn(function()
				GunSounds.GunReloaded:Play()
			end)
			if Character:FindFirstChild("Humanoid") then
				GunAnimations.GunReloading:Play()
			end
			Bullets = Bullets + 1
			Reloading = false
		end
	end;
end)

Revolver.Unequipped:Connect(function(Cursor)
	if Revolver and Unequipped then return end
	Unequipped = true
	spawn(function()
		GunSounds.GunEquipped:Play()
	end)
	Equipped = false
	--//
end)

Thank you

4 comments

0

ur gun is in a mess

0

Only problem I can see off the bat is your reloading. Since there's no delay, it reloads instantly. Mind giving more context, errors, etc?

0

thank you, I'll be sure to work on that, I knew I forgot something, I spent too long debugging before I could remember to put the delay

0

But I'm more concerned as the print("Fired") isn't being, Fired. It's not even reading the Click

1 answer

I think you could use another method. Activated isn't specific enough, so Using mousebutton might work better

mouse = Player:GetMouse()
Revolver.Equipped:Connect(function(Cursor)
mouse.MouseButton1Click:connect(function()
 if Revolver and not Reloading then return end
    Fired = true
    print("GunFired")
    if Revolver and Player then
        spawn(function()
            GunSounds.GunFired:Play()
        end)
        Bullets = Bullets - 1
        if Bullets < 1 then
            Reloading = true
        end;
        if Reloading then
            spawn(function()
                GunSounds.GunReloaded:Play()
            end)
            if Character:FindFirstChild("Humanoid") then
                GunAnimations.GunReloading:Play()
            end
            Bullets = Bullets + 1
            Reloading = false
        end
    end;
end)
    if Revolver and Equipped then return end
    Equipped = true
    if Revolver and Player then
        spawn(function()
            GunSounds.GunEquipped:Play()
        end)
        if Character:FindFirstChild("Humanoid") then
            GunAnimations.GunEquiping:Play()
        end
    end;
    Unequipped = false
end)


2 comments

0

Thanks, but I believe "mouse" is unnecessary as I've already got 'Cursor' defined through the tool Event, can't I just use that instead or must I work direct?

0

Well cursor compared to mouse is a little different. Cursor is the x and y position of the mouse cursor. Mouse is used to define if left and right click has been activated.

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