i am trying to make an randomizer position part with magnitude but it don’t work well
this is the code:
local X,Z,Y = ran:NextNumber(workspace.PortalV2.StarPos.Position.X - (workspace.PortalV2.StarPos.Size.X / 2),workspace.PortalV2.StarPos.Position.X + (workspace.PortalV2.StarPos.Size.X / 2)),ran:NextNumber(workspace.PortalV2.StarPos.Position.Z - (workspace.PortalV2.StarPos.Size.Z / 2),workspace.PortalV2.StarPos.Position.Z + (workspace.PortalV2.StarPos.Size.Z / 2)),ran:NextNumber(workspace.PortalV2.StarPos.Position.Y - (workspace.PortalV2.StarPos.Size.Y / 2),workspace.PortalV2.StarPos.Position.Y + (workspace.PortalV2.StarPos.Size.Y / 2))
local model = Instance.new("Model",workspace.PortalV2)
local star = Instance.new("Part",model)
star.Anchored = true
star.CanCollide = false
local ballmesh = Instance.new("SpecialMesh",star)
ballmesh.MeshType = Enum.MeshType.Sphere
star.Size = Vector3.new(0.5,0.5,0.5)
star.Position = Vector3.new(X,Y,Z)
star.Color = Color3.fromRGB(255, 255, 255)
star.Material = Enum.Material.Neon
while true do
X,Z,Y = ran:NextNumber(workspace.PortalV2.StarPos.Position.X - (workspace.PortalV2.StarPos.Size.X / 2),workspace.PortalV2.StarPos.Position.X + (workspace.PortalV2.StarPos.Size.X / 2)),ran:NextNumber(workspace.PortalV2.StarPos.Position.Z - (workspace.PortalV2.StarPos.Size.Z / 2),workspace.PortalV2.StarPos.Position.Z + (workspace.PortalV2.StarPos.Size.Z / 2)),ran:NextNumber(workspace.PortalV2.StarPos.Position.Y - (workspace.PortalV2.StarPos.Size.Y / 2),workspace.PortalV2.StarPos.Position.Y + (workspace.PortalV2.StarPos.Size.Y / 2))
local currentpos = Vector3.new(X,Y,Z)
for i,lastpos in pairs(model:GetChildren()) do
if lastpos:IsA("Part") then
while (lastpos.Position - currentpos).Magnitude <= 100 do
X,Z,Y = ran:NextNumber(workspace.PortalV2.StarPos.Position.X - (workspace.PortalV2.StarPos.Size.X / 2),workspace.PortalV2.StarPos.Position.X + (workspace.PortalV2.StarPos.Size.X / 2)),ran:NextNumber(workspace.PortalV2.StarPos.Position.Z - (workspace.PortalV2.StarPos.Size.Z / 2),workspace.PortalV2.StarPos.Position.Z + (workspace.PortalV2.StarPos.Size.Z / 2)),ran:NextNumber(workspace.PortalV2.StarPos.Position.Y - (workspace.PortalV2.StarPos.Size.Y / 2),workspace.PortalV2.StarPos.Position.Y + (workspace.PortalV2.StarPos.Size.Y / 2))
currentpos = Vector3.new(X,Y,Z)
local star = Instance.new("Part",model)
star.Anchored = true
star.CanCollide = false
local ballmesh = Instance.new("SpecialMesh",star)
ballmesh.MeshType = Enum.MeshType.Sphere
star.Size = Vector3.new(0.5,0.5,0.5)
star.Position = currentpos
star.Color = Color3.fromRGB(255, 255, 255)
star.Material = Enum.Material.Neon
print((lastpos.Position - currentpos).Magnitude)
end
end
end
end
i tried to put in while true to an instant result but it don’t work well i don’t want to use wait() because its not THAT fast
any help?