Improving opportunity system

I made this script just to test out if i can make a opportunity system like fnaf but i feel like the one i made isnt really efficient.

Is there anything i could improve on here?
I know i dont add enought comments its something i made quickly so i didnt see the need to add comments if im not using it for the long run i just wanted to know if theres anything in this script that could be improved

Thanks!

--// Services //--
local RS: ReplicatedStorage = game:GetService("ReplicatedStorage")

--// Models //--
local Hallucination = RS:WaitForChild("Hallucination"):Clone()
local HallucinationRoot = Hallucination.HumanoidRootPart
local PointsFolder = workspace.Points
Hallucination.Parent = workspace

--// Variables //--
local Lvl = Hallucination.LVL.Value
local Position = Hallucination.Position.Value
local Finished = false

Lvl = math.clamp(Lvl, 1, 20)
Position = math.clamp(Position, 1, 4)

local number = 0

--// Main Code //--
print(Lvl, Position)

while not Finished do
	number = math.random(1, 5)
	print("Random Number:", number)

	if number <= Lvl then
		Position = Position + 1
		print("Lvl:", Lvl, "Position:", Position)

		if Position == 1 then
			HallucinationRoot.CFrame = PointsFolder["Point 1"].CFrame
		elseif Position == 2 then
			HallucinationRoot.CFrame = PointsFolder["Point 2"].CFrame
		elseif Position == 3 then
			HallucinationRoot.CFrame = PointsFolder["Point 3"].CFrame
		elseif Position == 4 then
			HallucinationRoot.CFrame = PointsFolder["Point 4"].CFrame
			Finished = true
		end
	end

	task.wait(5)  -- Wait for a second before repeating
end
1 Like

I would rather use the scripting support tag for your post, than the creations feedback.

well it is a done script and working as i intended, i just wanted peoples opinion on what I could improve on but sure ill change it

1 Like

Instead of that huge if elseif part, I would just do:

HallucinationRoot.CFrame = PointsFolder:FindFirstChild("Point "..Position).CFrame
1 Like

thanks for this tip i didnt know you could call parts this way.