I am trying to get a part to teleport to a certain spot and change size if it selected by random on a table. The part changes size like it should but it is way above where it should be. I have no idea why this is happening. Here's my script
local zoneq1 = game.Workspace.ZoneQ1 local zoneq2 = game.Workspace.ZoneQ2 local zoneq3 = game.Workspace.ZoneQ3 local zoneq4 = game.Workspace.ZoneQ4 local zoneSelect = math.random(1, 4) if zoneSelect == 1 then zoneq1.Size = Vector3.new(1024, 246, 1024) zoneq1.Position = Vector3.new(509.5, 82.481, 511.5) end if zoneSelect == 2 then zoneq2.Size = Vector3.new(1024, 246, 1024) zoneq2.Position = Vector3.new(-514.5, 82.481, 511.5) end if zoneSelect == 3 then zoneq3.Size = Vector3.new(1024, 246, 1024) zoneq3.Position = Vector3.new(-514.5, 82.481, -512.5) end if zoneSelect == 4 then zoneq4.Size = Vector3.new(1024, 246, 1024) zoneq4.Position = Vector3.new(509.5, 82.481, -512.5) end
im not getting any errors or anything but the position of zoneq4 is 509.5, 305, -512.5 which is just higher. It might be that there is other parts and terrain where it would be if the position is correct but still I don't understand why it isn't going to the position I told it to. Thank you :)
It's due to the fact that you're using Position
rather than CFrame
. When Positioning a part using the Position property, the part will automatically move to the nearest place that can accommodate its size. To fix this, simply use CFrame. Positioning using CFrame is very similar to using the Position property. Your updated code would be:
local zoneq1 = game.Workspace.ZoneQ1 local zoneq2 = game.Workspace.ZoneQ2 local zoneq3 = game.Workspace.ZoneQ3 local zoneq4 = game.Workspace.ZoneQ4 local zoneSelect = math.random(1, 4) if zoneSelect == 1 then zoneq1.Size = Vector3.new(1024, 246, 1024) zoneq1.CFrame = CFrame.new(509.5, 82.481, 511.5) end if zoneSelect == 2 then zoneq2.Size = Vector3.new(1024, 246, 1024) zoneq2.CFrame = CFrame.new(-514.5, 82.481, 511.5) end if zoneSelect == 3 then zoneq3.Size = Vector3.new(1024, 246, 1024) zoneq3.CFrame = CFrame.new(-514.5, 82.481, -512.5) end if zoneSelect == 4 then zoneq4.Size = Vector3.new(1024, 246, 1024) zoneq4.CFrame = CFrame.new(509.5, 82.481, -512.5) end
More information on CFrames can be found here. I just like to warn you CFrame are very complicated.