How to do this?

Basically, I’m making a spawner and I want the items that spawn to be oriented a specific way, but it just doesn’t work. I’m using PivotTo: because it allows the hitbox inside the part to also be teleported. I know there is a way by making the spawner rotate a specific way first before spawning, but that just sounds like spaghetti code waiting to happen. Is there a way to solve this?

local module = game:GetService("ServerStorage"):WaitForChild("WeaponList")
local modulescript = require(module)
local itemtable = modulescript.RandomizeWeapon(chances)
local spawnlist = modulescript.WeaponList(List)

local handles = game.ServerStorage:WaitForChild("HandleList")
local item
local spawned = false
local debugmode = false
debugmode = true
local function randomzier(randomitem)
	local counter = 0
	local base = math.random(1,100)
for i,v in pairs(itemtable) do
		counter = counter + v
		if base <= counter then
			item = spawnlist[i]
			local tool = handles:FindFirstChild(item)
			if not tool then
				warn("Error 402: Handle '".. item.. "' can't be found")
				return
			end
			if spawned == false then
				-- enable value debug if you want print statement below to run
				if debugmode == true then
				print("Success! Handle '".. item .. "' has been successfully spawned, rarity: ".. itemtable[i] .. "%")
				end
		local clone = tool:Clone()
				if item == "FryingPan" then
					script.Parent.Orientation = Vector3.new(0,0,90)
				end
				clone:PivotTo(script.Parent.CFrame)
				task.wait()
				clone.Parent = script.Parent
				script.Parent.Orientation = Vector3.new(0,0,0)
			spawned = true
		end
	end
		end
end
while true do
	randomzier()
	task.wait(2)
	if script.Parent:FindFirstChildOfClass("Part") or script.Parent:FindFirstChildOfClass("UnionOperation") or  script.Parent:FindFirstChildOfClass("Model") or  script.Parent:FindFirstChildOfClass("MeshPart") then
	else
		spawned = false
	end
end
1 Like

Do you mean like you want it to keep its previous orientation? You can get the Euler Angles.

clone:PivotTo(script.Parent.CFrame * CFrame.Angles(clone.CFrame:ToEulerAnglesXYZ()))
2 Likes

look into CFrames a little more.

Changing a part’s rotation is easy.

1 Like


Why would this be happening?

thats spelled Euler, not Eular

1 Like

Thank you and @12345koip for helping me with this!

1 Like

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