I built and placed 100’s of basic wooden fences, I then created variations of different fences for a script to decide randomly which ones shall get switched out and stay default.
The problem I’m having is placing and orienting said fences after they get cloned. They don’t change position as they should or orientation and the script throws no errors when I run it in the command bar.
any help would be appreciated, thanks in advance.
–said script
local Common = {"Broken_Top_Fence", "Wood_Fence_Bent_Top", "Wood_Fence_Broken_Top"}
local Uncommon = {"Broken_One_Side_Fence","Slanted_Fence"}
local Rare = {"Fence_Falling_Apart", "Collapsing_Fence"}
for a, b in ipairs(workspace:GetChildren()) do print(a.."/"..#workspace:GetChildren())
if b.Name == ("Wood_Fence") then print("Got wood fence!")
local decider = math.random(1,100)
local rando_Fence = nil
local x, y, z = b.WorldPivot.Rotation:ToOrientation()
if decider <= 40 then
rando_Fence = ("Wood_Fence")
elseif decider <= 63 then
rando_Fence = Common[math.random(1,#Common)]
elseif decider <= 81 then
rando_Fence = Uncommon[math.random(1,#Uncommon)]
elseif decider <= 100 then
rando_Fence = Rare[math.random(1,#Rare)]
end
print("Rarity = "..decider)
local Fence_Piece = workspace:FindFirstChild(rando_Fence):Clone()
Fence_Piece.Parent = workspace
print("Parented "..Fence_Piece.Name)
local Rot_Dec = math.random(1,2)
--[[where the error is]]
if Rot_Dec == 1 then print("Reg rotation")
b:SetPrimaryPartCFrame(CFrame.new(b.WorldPivot.Position.X,b.WorldPivot.Position.Y, b.WorldPivot.Position.Z ) * CFrame.Angles(math.rad(math.deg(x)),math.rad(math.deg(y)),math.rad(math.deg(z))))
else print("Rotated_sideways")
b:SetPrimaryPartCFrame(CFrame.new(b.WorldPivot.Position.X,b.WorldPivot.Position.Y, b.WorldPivot.Position.Z ) * CFrame.Angles(math.rad(math.deg(x)),math.rad(math.deg(y*-1)),math.rad(math.deg(z))))
end
--[[where the error ends]]
b:Destroy()
end
wait()
end