So I'm trying to make a slot machine, and it works! But I'm trying to make it so you need to pay 1 token (a leaderstats value) to use it. The tokens value starts at 0 and you need to pay 12 of your balance value at a shop to get 1 token, except even if I buy a token, the slot machine script still thinks I have 0 tokens. How do I fix this? (It's in a normal script.)
Also I'm new to scriptinghelpers, so sorry if the format looks all trashy!
local display1 = script.Parent.Parent.Parent.Display1
local display2 = script.Parent.Parent.Parent.Display2
local display3 = script.Parent.Parent.Parent.Display3
local soundPart = script.Parent.Parent.Parent.SoundPart
gainedMoney = 0
name = "Balance"
images = {
"http://www.roblox.com/asset/?id=6803385707",
"http://www.roblox.com/asset/?id=6803388696",
"http://www.roblox.com/asset/?id=6803386284",
"http://www.roblox.com/asset/?id=6803386977",
"http://www.roblox.com/asset/?id=6803383975"
}
v = false
display1.Decal.Texture = images[math.random(1,5)]
display2.Decal.Texture = images[math.random(1,5)]
display3.Decal.Texture = images[math.random(1,5)]
script.Parent.Triggered:Connect(function(plr)
local asphalt = plr:FindFirstChild("leaderstats")
if asphalt then
if v == false then
v = true
plr.leaderstats.Tokens.Value = plr.leaderstats.Tokens.Value - 1
plr.Character.Humanoid.WalkSpeed = 0
script.Parent.Enabled = false
soundPart.Insert:Play()
wait(0.9)
soundPart.Pull:Play()
wait(0.3)
soundPart.Start:Play()
local v1 = 0
repeat
display1.Decal.Texture = images[math.random(1,5)]
v1 = v1 + 1
wait(0.1)
until v1 == 10
soundPart.Stop:Play()
local v2 = 0
repeat
display2.Decal.Texture = images[math.random(1,5)]
v2 = v2 + 1
wait(0.1)
until v2 == 10
soundPart.Stop:Play()
local v3 = 0
repeat
display3.Decal.Texture = images[math.random(1,5)]
v3 = v3 + 1
wait(0.1)
until v3 == 10
soundPart.Stop:Play()
--Outcomes
wait(.5)
if display1.Decal.Texture == "http://www.roblox.com/asset/?id=6803385707" and display2.Decal.Texture == "http://www.roblox.com/asset/?id=6803385707" then
plr.leaderstats.Balance.Value = plr.leaderstats.Balance.Value + 6
soundPart.Win:Play()
wait(4.8)
elseif display1.Decal.Texture == "http://www.roblox.com/asset/?id=6803385707" and display2.Decal.Texture == "http://www.roblox.com/asset/?id=6803385707" and display3.Decal.Texture == "http://www.roblox.com/asset/?id=6803385707" then
plr.leaderstats.Balance.Value = plr.leaderstats.Balance.Value + 12
soundPart.Win:Play()
wait(4.8)
elseif display1.Decal.Texture == "http://www.roblox.com/asset/?id=6803388696" and display2.Decal.Texture == "http://www.roblox.com/asset/?id=6803388696" then
plr.leaderstats.Balance.Value = plr.leaderstats.Balance.Value + 12
soundPart.Win:Play()
wait(4.8)
elseif display1.Decal.Texture == "http://www.roblox.com/asset/?id=6803388696" and display2.Decal.Texture == "http://www.roblox.com/asset/?id=6803388696" and display3.Decal.Texture == "http://www.roblox.com/asset/?id=6803388696" then
plr.leaderstats.Balance.Value = plr.leaderstats.Balance.Value + 24
soundPart.Win:Play()
wait(4.8)
elseif display1.Decal.Texture == "http://www.roblox.com/asset/?id=6803386284" and display2.Decal.Texture == "http://www.roblox.com/asset/?id=6803386284" then
plr.leaderstats.Balance.Value = plr.leaderstats.Balance.Value + 24
soundPart.Win:Play()
wait(4.8)
elseif display1.Decal.Texture == "http://www.roblox.com/asset/?id=6803386284" and display2.Decal.Texture == "http://www.roblox.com/asset/?id=6803386284" and display3.Decal.Texture == "http://www.roblox.com/asset/?id=6803386284" then
plr.leaderstats.Balance.Value = plr.leaderstats.Balance.Value + 36
soundPart.Win:Play()
wait(4.8)
elseif display1.Decal.Texture == "http://www.roblox.com/asset/?id=6803386977" and display2.Decal.Texture == "http://www.roblox.com/asset/?id=6803386977" then
plr.leaderstats.Balance.Value = plr.leaderstats.Balance.Value + 36
soundPart.Win:Play()
wait(4.8)
elseif display1.Decal.Texture == "http://www.roblox.com/asset/?id=6803386977" and display2.Decal.Texture == "http://www.roblox.com/asset/?id=6803386977" and display3.Decal.Texture == "http://www.roblox.com/asset/?id=6803386977" then
plr.leaderstats.Balance.Value = plr.leaderstats.Balance.Value + 48
soundPart.Win:Play()
wait(4.8)
elseif display1.Decal.Texture == "http://www.roblox.com/asset/?id=6803383975" and display2.Decal.Texture == "http://www.roblox.com/asset/?id=6803383975" then
plr.leaderstats.Balance.Value = plr.leaderstats.Balance.Value + 48
soundPart.Win:Play()
wait(4.8)
elseif display1.Decal.Texture == "http://www.roblox.com/asset/?id=6803383975" and display2.Decal.Texture == "http://www.roblox.com/asset/?id=6803383975" and display3.Decal.Texture == "http://www.roblox.com/asset/?id=6803383975" then
plr.leaderstats.Balance.Value = plr.leaderstats.Balance.Value + 100
soundPart.Win:Play()
wait(4.8)
else
soundPart.Lost:Play()
end
v = false
plr.Character.Humanoid.WalkSpeed = 16
script.Parent.Enabled = true
end
end
end

2 comments
I'm also not too experienced but I'm still learning
Question: does the vending machine still work with 0 tokens, or does it not work?