So, here is my issue:
I want to make it so a part is being created on the players Torso, then the part will move towards where the player is looking. Thing is: I have no idea how to do it, since I have never touched velocity. Part Creation Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage") local RemoteEvent = ReplicatedStorage:WaitForChild("LazerEvent") RemoteEvent.OnServerEvent:Connect(function(player) local part = game.ServerStorage.Lazer:Clone() local velocity = Instance.new("BodyVelocity", part) part.Parent = workspace part.Position = player.Character.Torso.Position part.CanCollide = false part.Anchored = true end)
Thanks for helping me.
You can move the piece to where the player's mouse is pointing, or where the player's head is pointing.
I will do it with the Mouse position, as it may be easier for your learning.
First, in LocalScript, when you activate RemoteEvent, remember to send LookVector Mouse, so that we can calculate the direction in which the projectile will be launched.
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local ReplicatedStorage = game:GetService("ReplicatedStorage") local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent") Mouse.Button1Down:Connect(function() local MouseLookVector = Mouse.Hit.LookVector RemoteEvent:FireServer(MouseLookVector ) end)
Now in ServerScriptService, to capture the Event
local ReplicatedStorage = game:GetService("ReplicatedStorage") local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent") local Velocity = 100 -- you can change this whenever you want local ServerStorage = game:GetService("ServerStorage") RemoteEvent.OnServerEvent:Connect(function(Player, MouseLookVector) -- now i will use your code. local part = ServerStorage.Lazer:Clone() local BodyVelocity = Instance.new("BodyVelocity", part) part.Parent = workspace part.Position = Player.Character.Torso.Position part.CanCollide = false part.Anchored = true BodyVelocity.Velocity = MouseLookVector * Velocity -- To make the projectile go in the right direction end)
I hope I helped, if you have any questions, you can ask me :)
Note: Your projectile cannot have Anchored = true, if Anchored is activated, BodyVelocity will have no effect on the body.