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)
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)