Exactly as it is here this code works, but if I take out the color property in the matrix (line 23) or reverse the orientation and color lines, the orientation fails to set and resets to default.
Why?!
local TweenService = game:GetService("TweenService") local wallgroup = script.Parent local tweeningInformation = TweenInfo.new( 3, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0 ) local centrepoint = 0 local wallsize = 20 local wallnumber = 1 xposition = centrepoint +(wallsize*wallnumber) wallgroup.Position = Vector3.new(xposition,yposition,zposition) while true do for i=1,6,1 do xposition = xposition + wallsize local wallgroupfinish = { CFrame = CFrame.new(xposition,0,0); Color = Color3.fromRGB(255,0,0); Orientation = Vector3.new(90,90,90) } local tweenmove = TweenService:Create(wallgroup,tweeningInformation,wallgroupfinish) tweenmove:Play() wait (4) end xposition = centrepoint +(wallsize*wallnumber) wallgroup.Position = Vector3.new(xposition,yposition,zposition) end
the orientation fails to set and resets to default.
I would assume its because you're also setting the CFrame
. Remember CFrame
is a matrix that contains a position, as well rotation. You're giving a default 0, 0, 0
orientation in the CFrame so it will keep setting it to that.
Multiply the CFrame by a rotation matrix CFrame.Angles(...)
and remove Orientation = Vector3.new(90,90,90)
from the tween properties table.
local rot = math.pi / 2 --// 90 degrees local wallgroupfinish = { CFrame = CFrame.new(xposition, 0, 0) * CFrame.Angles(rot, rot, rot) --// apply cframe with position and rotation, Color = Color3.new(1, 0, 0) --// set color to bright red (255, 0, 0) }
Also we are using math.pi / 2
since pi / 2
radians in 90
degrees. CFrame.Angles
takes radians not degrees but if you want to use degrees you can use math.rad(x)
and pass that. Also I'm setting a variable rot
so we can cut down on the amount of operations the lua VM has to process and i'm using Color3.new
since you're setting the color to an absolute value of 255
for red.