Cannot change Position.X,Y,Z in a tween

I wanted to make an object that moves to waypoints,but it clips into the ground so i wanted to make it only change its X and Z coordinates,but for some reason TweenService just doesnt count this as a property or something?.
The error is “Workspace.Sweep.Hitbox.Script:14: attempt to index nil with ‘X’”

Heres the script

local Sweep = script.Parent
local TweenService = game:GetService("TweenService")
local Info = TweenInfo.new(3)

local SweepWaypoints = workspace.Waypoints.Sweep

local SweepWaypointTable = {}
SweepWaypointTable = SweepWaypoints:GetChildren()

print(SweepWaypointTable[math.random(1,#SweepWaypoints:GetChildren())])


local goals1 = {}
goals1.Position.X = SweepWaypointTable[math.random(1,#SweepWaypoints:GetChildren())].Position.X -- Here
goals1.Position.Z = SweepWaypointTable[math.random(1,#SweepWaypoints:GetChildren())].Position.Z

local function woohowtghoarytg()
	local Tween1 = TweenService:Create(Sweep,Info,{Position = SweepWaypointTable[math.random(1,#SweepWaypoints:GetChildren())].Position})
	
	
	Tween1:Play()
	Tween1.Completed:Wait()
	woohowtghoarytg()
end
woohowtghoarytg()

How can i fix it?
Thanks in advance.

1 Like

You should do this, the whole position value should be a Vector3.new(X,Y,Z)

local goals1 = {}
goals1.Position = Vector3.new(SweepWaypointTable[math.random(1,#SweepWaypoints:GetChildren())].Position.X, 0, SweepWaypointTable[math.random(1,#SweepWaypoints:GetChildren())].Position.Z)

Plus, maybe you wanna change the CFrame and not the position, happens a lot to me, that I prefer to change the CFrame instead of Position, specially if there are more parts welded to the part you are moving

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.