How to make a chance of a certain GUI enabling?

I have a mirror in game that when interacted with a proximity prompt, will enable a GUI imagelabel on a player’s screen. I have two verisions of this GUI decal, one normal one and one not normal one. I want to make it a something in x chance or x% chance of the not normal decal enabling rather than the normal GUI but I have limited knowledge in scripting alone and am completely new to introducing chance in a script.

How would I make it so there is a let’s say, 10% chance/1 in 10 chance of the not normal GUI showing up? Would I need to use something like a chance list?

I have tried using a chance list but I guess I’m doing something wrong because then it breaks the entire script. I think my issue is that I’m getting confused with making sure that the GUI that shows up and goes away when the proximity prompt is interacted with.

This is the current script I have that enables the normal decal GUI, it doesn’t include anything to do with the not normal decal:

local proximity = workspace.MirrorPrompt.ProximityPrompt -- the proximity prompt itself in workplace
local ProximityPromptService = game:GetService("ProximityPromptService")

proximity.Triggered:Connect(function()
	local GUI = script.Parent:WaitForChild("MirrorNormal") -- normal mirror GUI
	GUI.Enabled = not GUI.Enabled
end)

local GUI = script.Parent:WaitForChild("MirrorNormal") 
GUI.Frame.TextButton.Activated:Connect(function()
	GUI.Enabled = not GUI.Enabled
end)

I think you would do something like:

local chance = {
normal,

normal,

normal,

normal,

not normal,

Like that and choose a random one, or pick a number

Use math.random to pick a number between 1, 10 and if the number falls on 1 then enable the GUI.

if math.random(1, 10) == 1 then
    -- enable gui
end

Wait, use also math.round as only math.random gives you decimal numbers

Not when you give it a range of integers.

Okay, I don’t know, I’m still new to scripting sorry :sweat_smile:

1 Like

Is this how I would apply it? Tried this script but it didn’t work for me.

local proximity = workspace.MirrorPrompt.ProximityPrompt -- the proximity prompt itself in workplace
local ProximityPromptService = game:GetService("ProximityPromptService")

if math.random(1, 2) == 1 then -- I set it to 1, 2 just to test if it's working
	proximity.Triggered:Connect(function()
		local GUI = script.Parent:WaitForChild("MirrorNormal") -- normal mirror GUI
		GUI.Enabled = not GUI.Enabled
	end)

	local GUI = script.Parent:WaitForChild("MirrorNormal") 
	GUI.Frame.TextButton.Activated:Connect(function()
		GUI.Enabled = not GUI.Enabled
	end)
	
elseif math.random(1, 2) == 2 then 
	proximity.Triggered:Connect(function()
		local GUI = script.Parent:WaitForChild("MirrorNotNormal") -- not normal mirror GUI
		GUI.Enabled = not GUI.Enabled
	end)

	local GUI = script.Parent:WaitForChild("MirrorNotNormal") 
	GUI.Frame.TextButton.Activated:Connect(function()
		GUI.Enabled = not GUI.Enabled
	end)
end

put the if statement in the connections, not outside

I dont understand why you dont do this:

Names = {"MirrorNormal", "MirrorNotNormal"} -- Names

local random = Names[math.random(1, #Names)] -- random Number by Number of index keys to get a Name
script.Parent[random].Enabled = not script.Parent[random].Enabled -- Enables based on Name


This won’t work if you want a new random chance every time you trigger the prompt.