Now that title might be confusing, but what I'm trying to do here is to clone a part when a tool gets activated. I then want to get the player's mouse position and set that as an end goal for the part to go to. After that, I use velocity to move the cloned part to that End Position. Now, my problem is that I want to have the starting part appear on the player's HumanoidRootPart position, but locate it a few studs in front of the player so that it doesn't bump into them.
Maybe my code will make more sense lol
local d = false
script.Parent.OnServerEvent:Connect(function(Player, MousePosition)
local HitObject = false
local StartPos = Player.Character.HumanoidRootPart.Position
local EndPos = MousePosition
local SDRoar = game.ServerStorage.SeaDragonRoar:Clone()
SDRoar.Parent = workspace
SDRoar.CFrame = CFrame.new(StartPos, EndPos)
-- Shoot the part
SDRoar.Velocity = SDRoar.CFrame.lookVector * 75
if SDRoar.Position == EndPos then
SDRoar:Destroy()
end
SDRoar.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and d == false and hit.Parent.Name ~= Player.Name then
d = true
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 20
wait(1)
d = false
SDRoar:Destroy()
end
end)
wait(5)
if HitObject == false then
SDRoar:Destroy()
end
end)
If you're going to answer this, I thank you for your time. :)
