Randomizing a custom function() before running it

1 What do you want to achieve?
making it so the script can randomize the function before running it, something like this


while true do

the custom functions are here

atTest()
HiTester()
Car1()

and then there’s a randomizer that will pick which custom function to run first, so like this.

it picks one of the custom functions

script is scanning in the randomizer part of the script (let’s just call it randomizer machine) then once the script picks one of the custom functions, it will then only run that custom function only.

(but since I’m using a WTD loop it will repeat forever and randomly pick a different one each time making it random)

  1. What is the issue? Include screenshots / videos if possible!
    it’s below
--Objects only

--all the parts are in ServerStorage from 1-3 and it works fine the only
--problem is that everytime you run the game it will only spawn the same part
--over and over not changing to a different part, and spawns a random one
--as you run the game each time.

local TestPart = game.ServerStorage.Part1
local TestPart1 = game.ServerStorage.Part2
local TestPart2 = game.ServerStorage.Part3
local NumberValueSides = script.Parent.Side.Value
local WaitSpawnTime = math.random(2,6)
local RandomNumber = math.random(1,3)


--local functions only
local function Car1()
	local CarPart = TestPart:Clone()
	CarPart.Parent = game.Workspace.Test_Spawner
end


local function Car2()
	local CarPart1 = TestPart1:Clone()
	CarPart1.Parent = game.Workspace.Test_Spawner
end


local function Car3()
	local CarPart2 = TestPart2:Clone()
	CarPart2.Parent = game.Workspace.Test_Spawner
end


--loop only
while true do
	wait(2)
	script.Parent.Side.Value = (RandomNumber)
	print("it spawned in " ..RandomNumber)
	wait(WaitSpawnTime)
	if NumberValueSides == 1 then
		Car1()
		print("Spawned in")
	end

	if NumberValueSides == 2 then
		Car2()
		print("Spawned in")
	end

	if NumberValueSides == 3 then
		Car3()
		print("Spawned in")
	end
end

Please do not write entire scripts or design entire systems.

Is this your problem? Its because you define RandomNumber only once.
Put the local RandomNumber = math.random(1,3) inside the loop so it’ll be random each time.

oh thanks, now it randomizes the numbers, when I look in the number value it changes the numbers which is good but thanks tho :slight_smile: