So I just need a system that moves a model randomly in an area(I have working) but ALSO faces the direction it moves. I can get it moving just fine, but if I try to add a direction to the CFrame is bugs out.
Here is the Error:
Workspace.Map.Home.PetHouse.Cat.Body.Script:23: Expected ')' (to close '(' at column 24), got ','
As far as I understand CFrame can point like this
CFrame.new(Pos, Rot)
But apparently I am wrong because I try to give it the target to rotate to and it wont accept it.
Here is the code:
local character = script.Parent.Parent local crame = character.PrimaryPart.CFrame local base = character.Parent.Base local sizeX, sizeZ = base.Size.X/2, base.Size.Z/2 local tweenService = game:GetService("TweenService") local info = TweenInfo.new() local xf = character.PrimaryPart.CFrame.X local zf = character.PrimaryPart.CFrame.Z local cf = Instance.new("CFrameValue") local function tweenpls(CF) local xspot = (xf + math.random(-sizeX, sizeX)) local zspot = (zf +math.random(-sizeZ, sizeZ)) local vpos = Vector3.new(xspot, 2.124, zspot) local tween = tweenService:Create( CF, TweenInfo.new(), {CFrame = CFrame.new((xspot, 2.124, zspot), vpos)} ) tween:Play() end while true do wait(2) --tweenModel(character.PrimaryPart, pos, vpos) tweenpls(character.PrimaryPart) crame = character.PrimaryPart.CFrame end
Not sure what it wants from me, I have tried turning the first parameter into its own CFrame.new and then it expects a vector 3, I try that and the model disappears and seems to start soaring around the map. Any help would be appreciated
You're missing a )
on line 23. You need one right after vpos)
and before the curly bracket }
. That's your error.
On line 23, the first parameter of CFrame.new(target, eye) expects a Vector3. You just gave it 3 values and surrounded with parenthesis.
Also, there are many CFrame constructors, but I don't remember one being CFrame.new(pos, rot). There is however CFrame.new(target, eye) which I believe is what you wanted.