Here is my code for a gun I want to tween the bullet to where it is facing. Anybody know how?
local player = game:GetService("Players").LocalPlayer local mouse = player:GetMouse() local tool = script.Parent tool.Activated:Connect(function() --Set Up local bullet = Instance.new("Part") --Size bullet.Size = Vector3.new(0.27,0.25,1.49) --Anchored bullet.Anchored = true --Can/Can Not Collide bullet.CanCollide = false --Color bullet.BrickColor = BrickColor.new("Really red") --Matirial bullet.Material = Enum.Material.Neon --Parent bullet.Parent = workspace --Positon bullet.Position = tool.Handle.Position + Vector3.new(0,0.5,0) --Angle bullet.CFrame = CFrame.new(bullet.CFrame.p, mouse.Hit.p) --Movement local TweenService = game:GetService("TweenService") local info = TweenInfo.new(3, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0) TweenService:Create(bullet, info, {Position = bullet.Position + Vector3.new(0,0,100)}):Play() end)
You've already adjusted the end Angle and start Position, so now you just want the Tween to end where ever your mouse clicked. This is Local, so other players won't see it, your next challenge will be working with RemoteEvents to notify the server and other players of your bullet.
Using mouse.Hit will Tween the part to the mouse CFrame
local info = TweenInfo.new(.15, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0) TweenService:Create(bullet, info, {CFrame = mouse.Hit}):Play()
Using lookVector will Tween the part past the click location
local info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0) TweenService:Create(bullet, info, {Position = bullet.CFrame.lookVector * 500 }):Play()