Need help with my random system

Hello, I’m new to roblox studio and i’m making a system like this.

local folder = script.Parent:WaitForChild("Statues")
local statues = folder:GetChildren()

local real_ball = script.Parent:WaitForChild("RealBall")
local fake_ball = script.Parent:WaitForChild("FakeBall")

local choosen_statue = statues[math.random(1, #statues)]

local function ball_placing()
	local choosen_statue_ball_placement = choosen_statue:WaitForChild("BallPlacement")
	real_ball.Position = choosen_statue_ball_placement.Position
	
	
end

print(choosen_statue.Name)
ball_placing()

So basically, I succeed at placing a “real ball” in a random statue between 4 statues.
And I want to place 3 fake balls (these fake balls are the same and can be clone) in 3 remaining statues. I was thinking about using for loops but I don’t know how to do it, someone pls help!

2 Likes

Maybe try placing fake balls in every statue already, then use random to pick any random statue, once picked change the fake balls parent inside the script so it’s not visible and clone the real ball into the choosen statue. If you understand how it works.

1 Like

Possibly try something like this to give all the fake balls to the remaining statues? (put after the real_ball position line in the function)

-- Loop through the statues
for i,v in pairs(statues) do
	-- If a statue is not the chosen one, place a fake ball
	if v ~= choosen_statue then
		local fake_ball_placement = v:WaitForChild("BallPlacement")
		-- Clones the fake ball and places it in the fake statue
		fake_ball:Clone().Position = fake_ball_placement.Position
	end
end
1 Like

your solution also worked, thank you!

1 Like