My Script with math.random ins't working

So i cannot understand “math.random” i was trying to make a Gas Station Robbery, when the wait time for the robbery is: “math.random(180, 220)” but both things won’t work the wait time and the random money! here is my code:

local handler = game:GetService(“Workspace”).Small_Stores.GasRobPart
local prompt = handler:WaitForChild(“ProximityPrompt”)
local robbed = game:GetService(“Workspace”).Small_Stores.GasRobPart.RobbedSmallStore

prompt.Triggered:connect(function(player)
robbed.Value = false
if robbed.Value == false then
player.leaderstats.Money.Value = player.leaderstats.Money.Value + math.random(650, 1500)
robbed.Value = true
if robbed.Value == true then
wait(math.random(180, 230))
robbed.Value = false
end
end
end)

Use this:

local handler = game:GetService("Workspace").Small_Stores.GasRobPart
local prompt = handler:WaitForChild("ProximityPrompt")
local robbed = game:GetService("Workspace".Small_Stores.GasRobPart.RobbedSmallStore

prompt.Triggered:connect(function(player)
	if robbed.Value == false then
		player.leaderstats.Money.Value = player.leaderstats.Money.Value + math.random(650, 1500)
		robbed.Value = true
		wait(math.random(180, 230))
		robbed.Value = false
	end
end)
1 Like

Oh my god, it worked , thank you so much! have a good day because you made mine!!!

1 Like

Hey something to add to @RobloxGamerPro200007 code. Use :Connect() and not :connect() for :connect() is deprecated by Roblox.

Also, use += instead of Number = Number + 1. That will make your code cleaner.

Also, it looks like there is a little typo in the robbed variable.

I also did if not Value instead of if Value == false then to simplify the code.

Here is the improved code.

local handler = game:GetService("Workspace").Small_Stores.GasRobPart
local prompt = handler:WaitForChild("ProximityPrompt")
local robbed = game:GetService("Workspace").Small_Stores.GasRobPart.RobbedSmallStore

prompt.Triggered:Connect(function(player)
	if not robbed.Value then
		player.leaderstats.Money.Value += math.random(650, 1500)
		robbed.Value = true
		wait(math.random(180, 230))
		robbed.Value = false
	end
end)
1 Like

Im so proud of you being here i din’t noticed i can use += than use the same thing again, you are so smart! Thanks i will try this out

1 Like