I Am making a stunning spell, There is a projectile, I Am trying to make the projectile face the LinearVelocity VectorVelocity.
It does go to the right direction…
I Did not find anything useful in the developer hub, Also, I Tried using lookout and it put the projectile in a different position I tried CFrame and positioning, but Nothing worked.
local Player = game.Players.LocalPlayer
script.Parent["Shoot projectile all clients"].OnClientEvent:Connect(function(Direction: Vector3, Character: Model)
local Projectile = game.ReplicatedStorage["Visual effects."].Projectile:Clone()
Projectile.Parent = workspace
for Index, Part in Projectile:GetChildren() do
if Part:IsA("LinearVelocity") then
Part.VectorVelocity = Direction * 100
end
end
Projectile.Position = Character.HumanoidRootPart.Position + Vector3.new(0,0,-5)
end)
I Tried that, All what happen it does not exist anymore, Do get cloned, Nothing, Just disappear.
local Projectile = game.ReplicatedStorage["Visual effects."].Projectile:Clone()
print(Player.Name)
Projectile.Parent = workspace
Projectile.Position = Character.HumanoidRootPart.Position
Projectile.CFrame = CFrame.lookAt(Projectile.Position, Direction)
for Index, Part in Projectile:GetChildren() do
if Part:IsA("LinearVelocity") then
Part.VectorVelocity = Direction * 100
end
end
Projectile.Parent = workspace
script["Shoot projectile all clients"]:FireAllClients(Direction, Character)
The second argument of your CFrame.lookAt call is incorrect, because a direction is an offset, not a world position.
Try this code:
local Player = game.Players.LocalPlayer
script.Parent["Shoot projectile all clients"].OnClientEvent:Connect(function(Direction: Vector3, Character: Model)
local Projectile = game.ReplicatedStorage["Visual effects."].Projectile:Clone()
Projectile.Parent = workspace
for Index, Part in Projectile:GetChildren() do
if Part:IsA("LinearVelocity") then
Part.VectorVelocity = Direction * 100
end
end
local Position = Character.HumanoidRootPart.Position + Vector3.new(0, 0, -5)
Projectile.CFrame = CFrame.lookAt(Position, Position + Direction)
end)