Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is my part not in the position I told it to be in?

Asked by 5 years ago

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 :)

1
Have you tried using CFrame instead? User#20279 0 — 5y
0
use CFrame. Vector 3 cant teleport out of walls. xXrawr_xdXxOwO 24 — 5y
0
Oh thanks. Better late than never lol oreoollie 649 — 5y

1 answer

Log in to vote
0
Answered by
oreoollie 649 Moderation Voter
5 years ago

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.

Ad

Answer this question