I am currently trying to make a basic gun tool. I have an issue with trying to set the projectile shooting. For some reason it seems like the bullet starts from where the mouse clicked towards the abyss. How would I fix this?
Hierarchy:
Server:
local debounce = false
script.Parent.Equipped:Connect(function()
script.Parent.Quack1:Play()
end)
script.Parent.Activated:Connect(function()
if debounce == false then
script.Parent.Launch.PlaybackSpeed = Random.new():NextNumber(0.8,1.2)
script.Parent.Launch:Play()
debounce = true
task.wait(0.1)
debounce = false
end
end)
script.Parent:WaitForChild("Fire").OnServerEvent:Connect(function(Player,MousePos)
local bullet = game.ServerStorage.Bullet:Clone()
local PersonWhoFired = bullet:WaitForChild("PersonWhoFired")
bullet.Parent = game.Workspace
PersonWhoFired.Value = Player.UserId
bullet.Anchored = false
bullet.CanCollide = true
bullet.Script.Enabled = true
local antiGravity = bullet.VectorForce
antiGravity.Force = Vector3.new(0, (workspace.Gravity * bullet:GetMass()), 0)
antiGravity.Parent = bullet
-- this is the line where the starting position is set
bullet.CFrame = script.Parent.Handle.CFrame * script.Parent.Handle.Attachment.CFrame
bullet.CFrame = CFrame.new(bullet.Position, MousePos)
bullet.Anchored = false
bullet.AssemblyLinearVelocity = CFrame.new(script.Parent.Handle.Position,MousePos).LookVector * 1000
return Player
end)