I’m trying to having the rotation of cactuses randomized everytime the map spawned in:
local mapstorage = game.Workspace.MapStorage
local cactus = script.Parent.Cactus:GetChildren()
game.Workspace.MapStorage.ChildAdded:Connect(function()
if mapstorage:FindFirstChild("Bone Desert") then
cactus.Rotation = Vector3.new(0, Random, 0)
else
return end
end)
local mapstorage = game.Workspace.MapStorage
local cactus = {
script.Parent.Cactus.a,
script.Parent.Cactus.b,
script.Parent.Cactus.c,
script.Parent.Cactus.d,
script.Parent.Cactus.e,
script.Parent.Cactus.f,
script.Parent.Cactus.g,
script.Parent.Cactus.h,
script.Parent.Cactus.i,
script.Parent.Cactus.j,
script.Parent.Cactus.k,
script.Parent.Cactus.l,
script.Parent.Cactus.m,
script.Parent.Cactus.n,
script.Parent.Cactus.o,
script.Parent.Cactus.p,
script.Parent.Cactus.q,
script.Parent.Cactus.r
}
game.Workspace.MapStorage.ChildAdded:Connect(function()
if mapstorage:FindFirstChild("Bone Desert") then
local x = math.random(0,360)
for i, Part in pairs(cactus) do
Part.Orientation = Vector3.new(0, x, 0);
end
end
end)
I think this should work? The parents and stuff might be wrong though
for _, Cactus in pairs(mapstorage["Bone Desert"].Cactus:GetChildren()) do
Cactus.CFrame *= CFrame.new(0, math.pi * math.random() * 2, 0)
end
This is assuming the cactuses are parts. If they’re models, make sure they have a primary part and use Cactus:SetPrimaryPartCFrame(Cactus.PrimaryPart.CFrame * CFrame.new(0, math.pi * math.random() * 2, 0))
local mapstorage = game.Workspace.MapStorage
local cactus = script.Parent.Cactus:GetChildren()
game.Workspace.MapStorage.ChildAdded:Connect(function()
if mapstorage:FindFirstChild("Bone Desert") then
local x = math.random(0,360)
cactus.Orientation = Vector3.new(0, x, 0);
end
end)
I tried this in studio and it worked. Script was in ServerScriptService
local Map = workspace.MapStorage
Map.ChildAdded:Connect(function(vMap)
if vMap.Name == "Bone Desert" then
for _, Cactus in pairs(vMap.Cactuses:GetChildren()) do
Cactus.CFrame *= CFrame.Angles(0, math.pi * math.random() * 2, 0)
end
end
end)
local mapstorage = game.Workspace.MapStorage
local cactus = script.Parent.Cactus:GetChildren()
game.Workspace.MapStorage.ChildAdded:Connect(function()
if mapstorage:FindFirstChild("Bone Desert") then
for i,v in pairs(cactus) do
local x = math.random(-180, 180)
v.Orientation = Vector3.new(0, x, 0);
end
end
end)