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

Why is my projectile not firing?

Asked by 3 years ago

local tool = script.Parent local projectile_shooter = tool.Handle local repstorage = game.ReplicatedStorage local bullet = repstorage:WaitForChild("Bullet") local effective_distance = 200 local speed = 200 local target = nil local dmg = 10 while tool.Equipped do wait() tool.Activated:Connect(function() for i, v in pairs(game.Workspace:GetChildren()) do local human = v:FindFirstChild("Humanoid") local torso = v:FindFirstChild("UpperTorso") if human and torso then local newray = Ray.new(projectile_shooter.Position, (torso.Position - projectile_shooter.Position).Unit * effective_distance) local hit, position = game.Workspace:FindPartOnRayWithIgnoreList(newray, {projectile_shooter}) if hit == torso then target = torso end end end if target then local torso = target projectile_shooter.CFrame = CFrame.new(projectile_shooter.Position, torso.Position) local newbullet = bullet:Clone() newbullet.Parent = game.Workspace newbullet.Position = projectile_shooter.Position newbullet.Velocity = projectile_shooter.CFrame.LookVector * speed newbullet.Touched:Connect(function(hit) local human = hit.Parent:FindFirstChild("Humanoid") if human then human:TakeDamage(dmg) end end) end end) end

I was watching a raycasting tutorial and modified some of the code to make a gun. For some reason the projectile is not firing. I would like some help as to why.

Answer this question