Hey,
I am relatively new to Roblox Lua and recently experimented with all sorts of projects. This time around, I worked on slot machines and merged them into a tiny experience.
What do you do? (Gameplay)
Gamble
Using in-game currency, you can try your luck at the slot machines. As you get luckier, you can progress to more expensive, but also more rewarding machines.
Beg
Beg your virtual mom character for money… if you should ever run out of it.
Leave
Use the car to leave and get different ‘endings’ (they’re not that spectacular) based on your profits. You’ll have to repay your mom however.
How does it work? (Programming)
Function to roll a slot
The function below takes the predetermined chances for the respective slot (a full number between 0 and 100, equivalent to %) and then returns a unique number based on an RNG value using math.random
.
local function getFinalSlot()
local rng = math.random(1, 100)
if rng <= baconChance then -- returns bacon slot
return 1
elseif rng <= baconChance + tophatChance then -- returns tophat slot
return 2
elseif rng <= baconChance + tophatChance + dominusChance then -- returns dominus slot
return 3
else
warn("Probabilities do not add up to 100!")
end
end
Payouts/slot evaluation
The last part of the machine code turns the slot combination into a string. Using conditional statements, rewards are(n’t) paid out based on the combination.
local slotCombination = tostring(s1FinalSlot..s2FinalSlot..s3FinalSlot)
if slotCombination == "113" then -- bacon, bacon, dominus
cashRemote:FireClient(player, reward1)
arcadeLosses.Value += reward1
screenText.Text = winningText
winSound:Play()
for i = 1, 3 do
wait(0.5)
screenText.TextTransparency = 1
wait(0.5)
screenText.TextTransparency = 0
end
elseif slotCombination == "111" then -- bacon, bacon, bacon
cashRemote:FireClient(player, reward2)
arcadeLosses.Value += reward2
screenText.Text = winningText
winSound:Play()
for i = 1, 3 do
wait(0.5)
screenText.TextTransparency = 1
screenLight.Enabled = false
wait(0.5)
screenText.TextTransparency = 0
screenLight.Enabled = true
end
... -- other winning combinations are here
else -- other combinations (lose)
screenText.Text = losingText
loseSound:Play()
for i = 1, 3 do
wait(0.5)
screenText.TextTransparency = 1
screenLight.Enabled = false
wait(0.5)
screenText.TextTransparency = 0
screenLight.Enabled = true
end
end
Feel free to DM me if you wish to learn more about the code. I’ve merely shown a fraction of it so far!
Is this allowed? (Roblox ToS)
Totally.
Roblox on gambling:
However, no real money, Robux, or in-experience items of value may be exchanged in connection with any gambling activities. We also require that the odds of winning be fair and clearly disclosed to the user prior to playing.
None of the above applies to this experience, meaning that there’s no money, Robux or valuable items involved. You can check the odds of winning by talking to the arcade owner NPC.
Let me know what you think!