I’m trying to spawn models and parts for my arcade dropper game as obstacles for when they drop a ball to get a score.
What is the issue?
When I try to set the position(Use MoveTo) for obstacles that are models, nothing happens. It sets rotation and CFrame but it doesn’t work using MoveTo.
Example showing what happens every time I try to spawn models:
local ServerStorage = game:GetService("ServerStorage")
local Debris = game:GetService("Debris")
local Obstacles = {}
function Obstacles.Spawn(number)
for i = 1,number do
local randomObstacle = math.random(1,#ServerStorage.Spawns:GetChildren())
local chosenObstacle = ServerStorage.Spawns:GetChildren()[randomObstacle]:Clone()
local arcade = workspace.Arcade
local slider = arcade.Spawn
local X = math.random(-slider.Size.X/2,slider.Size.X/2)
local Y = math.random(-slider.Size.Y/2,slider.Size.Y/2)
local Z = math.random(-slider.Size.Z/2,slider.Size.Z/2)
if chosenObstacle:IsA("BasePart") then
chosenObstacle.CFrame = slider.CFrame
chosenObstacle.Position = chosenObstacle.Position + Vector3.new(X,Y,Z)
elseif chosenObstacle:IsA("Model") then
local randoms = {
CFrame.Angles(0,math.rad(90),0),
CFrame.Angles(0,math.rad(-90),0)
}
local random = math.random(1,#randoms)
local chosen = randoms[random]
chosenObstacle:PivotTo(slider.CFrame * chosen)
chosenObstacle:MoveTo(chosenObstacle.PrimaryPart.Position + Vector3.new(X,Y,Z))
end
chosenObstacle.Parent = arcade.Obstacles
end
end
function Obstacles:Change(number)
for _,obstacle in workspace.Arcade.Obstacles:GetChildren() do
if obstacle then
Debris:AddItem(obstacle,.1)
end
end
self.Spawn(number)
end
return Obstacles
Tweak some of it …
Hard to be sure without a way to test it.
local ServerStorage = game:GetService("ServerStorage")
local Debris = game:GetService("Debris")
local Obstacles = {}
function Obstacles.Spawn(number)
for i = 1, number do
local randomObstacle = math.random(1, #ServerStorage.Spawns:GetChildren())
local chosenObstacle = ServerStorage.Spawns:GetChildren()[randomObstacle]:Clone()
local arcade = workspace.Arcade
local slider = arcade.Spawn
local X = math.random(-slider.Size.X/2, slider.Size.X/2)
local Y = math.random(-slider.Size.Y/2, slider.Size.Y/2)
local Z = math.random(-slider.Size.Z/2, slider.Size.Z/2)
if chosenObstacle:IsA("BasePart") then
chosenObstacle.CFrame = slider.CFrame
chosenObstacle.Position = chosenObstacle.Position + Vector3.new(X, Y, Z)
elseif chosenObstacle:IsA("Model") then
local randoms = {
CFrame.Angles(0, math.rad(90), 0),
CFrame.Angles(0, math.rad(-90), 0)
}
local random = math.random(1, #randoms)
local chosen = randoms[random]
chosenObstacle:SetPrimaryPartCFrame(slider.CFrame * chosen)
chosenObstacle:SetPrimaryPartCFrame(chosenObstacle.PrimaryPart.CFrame + Vector3.new(X, Y, Z))
end
chosenObstacle.Parent = arcade.Obstacles
end
end
function Obstacles:Change(number)
for _, obstacle in ipairs(workspace.Arcade.Obstacles:GetChildren()) do
if obstacle then
Debris:AddItem(obstacle, 0.1)
end
end
self.Spawn(number)
end
return Obstacles
local ServerStorage = game:GetService("ServerStorage")
local Debris = game:GetService("Debris")
local Obstacles = {}
function Obstacles.Spawn(number)
for i = 1, number do
local randomObstacle = math.random(1, #ServerStorage.Spawns:GetChildren())
local chosenObstacle = ServerStorage.Spawns:GetChildren()[randomObstacle]:Clone()
local arcade = workspace.Arcade
local slider = arcade.Spawn
local X = math.random(-slider.Size.X/2, slider.Size.X/2)
local Y = math.random(-slider.Size.Y/2, slider.Size.Y/2)
local Z = math.random(-slider.Size.Z/2, slider.Size.Z/2)
if chosenObstacle:IsA("BasePart") then
chosenObstacle.CFrame = slider.CFrame * CFrame.new(X, Y, Z)
elseif chosenObstacle:IsA("Model") then
local randoms = {
CFrame.Angles(0, math.rad(90), 0),
CFrame.Angles(0, math.rad(-90), 0)
}
local random = math.random(1, #randoms)
local chosen = randoms[random]
chosenObstacle.CFrame = slider.CFrame * chosen * CFrame.new(X, Y, Z)
end
chosenObstacle.Parent = arcade.Obstacles
end
end
function Obstacles:Change(number)
for _, obstacle in ipairs(workspace.Arcade.Obstacles:GetChildren()) do
if obstacle then
Debris:AddItem(obstacle, 0.1)
end
end
self.Spawn(number)
end
return Obstacles
welp … you can put a part in model … set the primary to the part.
Then control the model or the primary part.
Guess i need to find a new way to avoid setprimarypartcframe