Gun parts (Animations, Shooting) doesn't work properly

Hey all! I’ve been developing on a game for a while now. Now I’m on the animation part, but for some reason the animation doesn’t play. And when I try to shoot now, it doesn’t shoot but it does add the bullet into the ‘Ignore’ folder in workspace.

Module (for 1 weapon)
local Settings = {
	--// Types
	WeaponType = "Automatic";
	Range = 700;
	FireRate = 650;
	Damage = math.random(10, 25);
	HeadDamage = math.random(30, 50);
	
	--// Objects
	Bullet = game:GetService("ReplicatedStorage"):WaitForChild("Bullets"):WaitForChild("P90_Bullet");
	
	--// Animations
	ShootingAnimation = "rbxassetid://7506963692";
	IdleAnimation = "rbxassetid://7515970037";
}

return Settings
Client
local function SendBackToMenu()
	for _, v in pairs(Weapons:GetChildren()) do
		if character:FindFirstChild(v.Name) then
			DisconnectWeaponRE:FireServer(character:FindFirstChild(v.Name))
		end
	end
end

local function NilCheckForWeapon(Weapon)
	if Weapons:FindFirstChild(Weapon) then
		FoundWeapon = Weapons:FindFirstChild(Weapon)
	else
		return
	end
	
	if Weapon_Settings:FindFirstChild(Weapon) then
		FoundWeaponSettings = require(Weapon_Settings:FindFirstChild(Weapon))
	else
		return
	end
end

NilCheckForWeapon("P90")

local function AddBullet(Weapon)
	if (FoundWeapon and FoundWeaponSettings) == nil then
		return
	else
		if not Shooting then
			Shooting = true
			
			local Muzzle = FoundWeapon:FindFirstChild("Muzzle")
			local RayFromMuzzleToMousePosition = Ray.new(Muzzle.CFrame.Position, (mouse.Hit.Position - Muzzle.CFrame.Position).Unit * FoundWeaponSettings.Range)
			local Hit, Position = workspace:FindPartOnRayWithIgnoreList(RayFromMuzzleToMousePosition, {character})

			if Hit then
				if Hit.Parent:FindFirstChild("Humanoid") then
					if Hit.Name == "Head" then
						Damage = FoundWeaponSettings.HeadDamage
					else
						Damage = FoundWeaponSettings.Damage
					end
				end

				ShootRE:FireServer(Hit, Position, Damage, FoundWeaponSettings.Bullet)
			end

			task.wait(60 / FoundWeaponSettings["FireRate"])
			Shooting = false
		end
	end
end

mouse.Button1Down:Connect(function()
	MouseButton1Down = true
	
	if (FoundWeapon and FoundWeaponSettings) == nil then
		return
	else
		if FoundWeaponSettings.WeaponType == Automatic then
			task.delay(0, function()
				while MouseButton1Down do
					if Shooting then
						break
					end
					
					AddBullet("P90")
					
					local ShootingAnim = Instance.new("Animation")
					ShootingAnim.AnimationId = FoundWeaponSettings["ShootingAnimation"]
					
					local LoadedShootingAnim = Animator:LoadAnimation(ShootingAnim)
					LoadedShootingAnim:Play()
				end
			end)
		end
	end
end)

mouse.Button1Up:Connect(function()
	MouseButton1Down = false
end)

SendClientCameraInfoRE.OnClientEvent:Connect(function()
	ActivateTransition(function()
		ThirdPersonCameraConnection = _Camera:ActivateThirdPerson()
	end)
	
	Deploy()
	
	if FoundWeapon and FoundWeaponSettings ~= nil then
		ConnectWeaponRE:FireServer(FoundWeapon, FoundWeaponSettings)
	end
end)
ServerRemotes
ShootRE.OnServerEvent:Connect(function(player, hit, pos, damage, bullet)
	if hit.Parent:FindFirstChild("Humanoid") then
		local humanoid = hit.Parent:FindFirstChild("Humanoid")

		if humanoid.Health > 0 then
			humanoid:TakeDamage(damage)
		end
	else
		local BulletClone = bullet:Clone()
		BulletClone.Position = pos
		BulletClone.Anchored = true
		BulletClone.CanCollide = false
		BulletClone.Parent = workspace:FindFirstChild("Ignore")
		game.Debris:AddItem(BulletClone, 5)
	end
end)

ConnectWeaponRE.OnServerEvent:Connect(function(Player, FoundWeapon, FoundWeaponSettings)
	local Character = Player.Character or Player.CharacterAdded:Wait()
	
	-- Weapon Customizing
	
	local WeaponClone = FoundWeapon:Clone()
	
	for _, v in pairs(WeaponClone:GetDescendants()) do
		if v:IsA("BasePart") then
			v.Anchored = false;
			v.CanCollide = false;
		end
	end
	
	if not WeaponClone:FindFirstChild("WeaponGrip") then
		local NewM6D = Instance.new("Motor6D")
		NewM6D.Name = "WeaponGrip"
		NewM6D.Parent = WeaponClone
		NewM6D.Part1 = Character:FindFirstChild("UpperTorso")
		NewM6D.Part0 = WeaponClone:FindFirstChild("BodyAttach")
	else
		local WeaponGrip = WeaponClone:FindFirstChild("WeaponGrip")
		WeaponGrip.Part1 = Character:FindFirstChild("UpperTorso")
		WeaponGrip.Part0 = WeaponClone:FindFirstChild("BodyAttach")
	end
	
	WeaponClone.Parent = Character
end)

DisconnectWeaponRE.OnServerEvent:Connect(function(Player, Weapon)
	Weapon:Destroy()
end)

For extra info, here’s the gun in ReplicatedStorage:

1 Like

Hello, can anybody please help? I’m still looking for a solution.

they probably don’t understand or confused about the code

maybe clarify your topic? I don’t seem to understand too

1 Like

So let’s first talk about the shooting. Check in the ServerRemotes there, I call the ShootRE event. The Shooting “works”. Basically it does get parented to the Ignore folder in workspace, but there’s no bullet or anything. Can’t find the bullet, whatsoever.

any images? ignore this, 30s

1 Like

But there’s no bullet in that position…

Edit: That gun inside my body (I aTe ThAt gUn MuaUahAHa)

Here’s what the bullet looks like:

ahahaha nice joke

also I saw the “Position” variable, and I think the “Position” you’re giving is your character, what was it supposed to be instead? is it the tree?

Which position in which script? (Can you quote it)

well, these ignore this, you guessed it, 30s

1 Like

I do believe the 2nd argument when calling workspace:FindPartOnRayWithIgnoreList() is the table to ignore.

Edit: Roblox API Reference hates me

can I see the “character” variable? I can’t find it in your code

I didn’t show most of the part of the script (Since I don’t wanna spoil my script :<)
But here is 1 of the part.

--// Player Variables
local camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
local PlayerGui = player:WaitForChild("PlayerGui")
local mouse = player:GetMouse()
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local Animator = humanoid:WaitForChild("Animator")
local HumanoidRootPart = character:WaitForChild("HumanoidRootPart")

It’s 1 part of the Client script (LocalScript)

Its probably because your while mousebutton1down loop is not inside the click detection event.

You can also solve this by making the “while button1down do” to a while true do, and put an if statement inside the loop. Make sure the wait() is outside the if statement

ex:
while true do
if button1down then
—Animation code
end
—wait here
end

edit: tried to format but on mobile :woman_shrugging:

edit 2: also i realized you did do this and i cant delete this reply

1 Like

Got anything new? I’m trying to fix this for 3-4 days now.