Simply multiply the head CFrame by another CFrame
It's weird how this is calculated, but it fits best with your problem. Lookvector is a property of all CFrames, and it tells which direction the CFrame is facing. Lookvector can be vary useful, but when you want to get a position from a CFrame, you can multiply it by another CFrame.
In our case, we want the CFrame to go behind the had and slightly above it. A positive Z is behind, and a Negitive Y is above.
To make a CFrame a Vector3, we just use the .p after the CFrame which turns it into a position.
local player = game.Players.LocalPlayer
local character = player.Character
local dexbot = script.Parent
local pos = dexbot.BodyPosition
while true do
wait()
pos.Position = (char.Head.CFrame * CFrame.new(0,3,2)).p
end
Doesn't work? Keep reading.
Still isn't working?
This is because you're either A.) Using a Local Script in workspace, or B.) Using Local Player in a regular script.
To fix this, get the player with the PlayerAdded event, and get the character with the CharacterAdded event. Also make sure to use a RegularScript.
game.Players.PlayerAdded:connect(function(plr)
plr.CharacterAdded:connect(function(char)
local dexbot = script.Parent
local pos = dexbot.BodyPosition
while true do
wait()
local c = char.Head.CFrame * CFrame.new(0,3,2)
pos.Position = c.p
end
end)
end)
If tested this and it works fine.
Cloning this to new players
Just use the Clone() function and set it to new players if you want them to all have the orb.
game.Players.PlayerAdded:connect(function(plr)
plr.CharacterAdded:connect(function(char)
local dexbot = script.Parent:Clone()
dexbot.Parent = workspace
local pos = dexbot.BodyPosition
while wait() do
pos.Position = (char.Head.CFrame * CFrame.new(0,3,2)).p
end
end)
end)
I tested this and it works fine.
I got all of the following information in the following places,
- eLunate's answer on how to get the position according to a CFrame
- Wiki Body Position
- Wiki CFrames
- Wiki PlayerAdded Examples
- Wiki CharacterAdded Examples
- Wiki Clone Function
Good Luck!
if I helped, please don't forget to accept my answer.