So. Im making a gun for a friend
I finished it then i started scripting it.
Now what i need is to make the 'local Bullet = Instance.new("Part",game.Workspace)' goes to the mouse position like in Phantom Force or Jailbreak.
I'm not asking for a script i'm just a noob in script and i don't know where to start.
Thanks
local player = game.Players.LocalPlayer -- Assuming this is a local script local char = player.CharacterAdded:wait() local mouse = player:GetMouse() local Bullet = Instance.new("Part",game.Workspace) local trajectory = CFrame.new(char.HumanoidRootPart.CFrame.p,mouse.Hit.p) -- Sets the bullet to character's HumanoidRootPart Position, while looking at the mouse's world Position. Bullet.Anchored = true Bullet.CFrame = trajectory local BV = Instance.new("BodyVelocity") BV.MaxForce = Vector3.new(math.huge,math.huge,math.huge) BV.Velocity = Bullet.CFrame.lookVector * 100 -- Multiplied by whatever speed you want.
Also if you want the bullet to spawn infront of the character replace the following line with this
Bullet.CFrame = trajectory *CFrame.new(0,0,-10) -- 10 studs infront of the character
And if you want the bullet to spawn out of the barrel of the gun, make sure you define it first
local barrel = GUNNAME.Barrel.CFrame.p local trajectory = CFrame.new(barrel,mouse.Hit.p) * CFrame.new(0,0,-2) -- 2 studs infront of the barrel
If this helped you, please accept this answer.
Bullet.CFrame = game.Players.LocalPlayer:GetMouse().Target
Does that work?