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

My Gun script is not creating a bullet neither shooting?

I don't know if my code is incomplete or it's just not it I shoot and it won't shoot any bullet do I need some CFrame or different properties please help me?

--Made By johndeer2233
player = game.Players.LocalPlayer
mouse = player:GetMouse()
tool = script.Parent
AnimationIdle = script:WaitForChild("IdleGun")
idleenabled = true
enabled = true
ChamberGun = script.Parent.ChamberGun

--All the Animations
script.Parent.Equipped:connect(function()
	   if enabled then
		enabled = false
		local AnimationTrackIdle = player.Character.Humanoid:LoadAnimation(script.IdleGun)
		AnimationTrackIdle:Play()
		print("It Worked!")
	end
	wait(5)
	enabled = true
end)
-- When SHooting
mouse.Button1Down:connect(function()
	local bullet = Instance.new("Part")
	bullet.Shape = "Ball"
	bullet.Size = Vector3.new(0.6, 0.6, 0.6)
	bullet.BrickColor = BrickColor.new("Medium Stone Grey")
	bullet.Position = ChamberGun.Position
	bullet.Velocity = Vector3.new(-100,0,0)
        bullet.Parent = ChamberGun
end)

There is no error in the output and the chamber gun position is the end of the gun and different part as well as it is set to CanCollide = false

1 comment

0

You're not setting where to Exactly to Shoot at.

1 answer

I hope you know how to dissect scripts, but here this could help you

local Tool = script.Parent
-- WebBall is the projectile created through "Instance.new()"
function shoot(v)
	local bullet = WebBall:Clone()

	local Character = tool.Parent
	local Head = Character:FindFirstChild("Head")
	bullet.Parent = workspace
	local launch = Head.Position + 10 * v
	bullet2.CFrame = CFrame.new( launch, launch + v)
	bullet.Velocity = v * 100
end

function fire()
	local Character = tool.Parent
	local Humanoid = Character:FindFirstChild("Humanoid")
	local look = (Humanoid.TargetPoint - Character:FindFirstChild("Head").Position).unit
	shoot(look)
end
Tool.Activated:connect(fire)

3 comments

0

Just a quick question where do you declare v as a variable

0

Where is weball declared to

0

Sorry, I fixed it now.

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