Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My betting gui always succeds, why dosen't it fail atleast once?

So, i made a betting gui, you select the amount, and you click the button. If you lose, you lose the amount of your betting money. If you win, your betting money will be doubled. The problem is: you always win. I've tested this, even restarting the game (clicking stop then test again).

Here's the code:

math.randomseed(tick())
script.Parent.MouseButton1Down:connect(function()
	local betmoney = tonumber(script.Parent.Parent.TextBox.Text)
	local playermoney = tonumber(game.Players.LocalPlayer.leaderstats.Money.Value)
	if betmoney > playermoney then
		print("lolno")
					script.Parent.Text = ("Error!")
			wait(1)
			script.Parent.Text = ("Bet")
	else
		if betmoney > 0 then
					script.Parent.Text = "Betting..."
		local profittable = {"true", "false"}
		local profit = profittable[math.random(2)]
		print(profit)
		if profit == "true" then
		game.Players.LocalPlayer.leaderstats.Money.Value = playermoney + betmoney
		script.Parent.Parent.Parent:Destroy()
		else
			game.Players.LocalPlayer.leaderstats.Money.Value = playermoney - betmoney
		script.Parent.Parent.Parent:Destroy()
		end
		else
			print("lolno")
			script.Parent.Text = ("Error!")
			wait(1)
			script.Parent.Text = ("Bet")
		end
	end

end)

2 answers

✓ Accepted answer

While this should work, it may help to select from a larger pool of numbers. You can also use actual boolean values true and false instead of strings:

math.randomseed(tick())
script.Parent.MouseButton1Down:connect(function()
	local betmoney = tonumber(script.Parent.Parent.TextBox.Text)
	local playermoney = tonumber(game.Players.LocalPlayer.leaderstats.Money.Value)
	if betmoney > playermoney then
		print("lolno")
		script.Parent.Text = ("Error!")
		wait(1)
		script.Parent.Text = ("Bet")
	else
		if betmoney > 0 then
			script.Parent.Text = "Betting..."
			local profit = (math.random(100) > 50) --// If the random number is more than 50, true. Otherwise, false.
			print(profit)
			if profit then --// If profit == true,
				game.Players.LocalPlayer.leaderstats.Money.Value = playermoney + betmoney
				script.Parent.Parent.Parent:Destroy()
			else --// Otherwise..
				game.Players.LocalPlayer.leaderstats.Money.Value = playermoney - betmoney
				script.Parent.Parent.Parent:Destroy()
			end
		else
			print("lolno")
			script.Parent.Text = ("Error!")
			wait(1)
			script.Parent.Text = ("Bet")
		end
	end
end)

Hope this helped.

PS: See how much more readable your code is when it's indented correctly? I urge you to check out these wiki pages about clean code and indenting. Good luck!

EDITED ON PYRONDON'S ANSWER



math.randomseed(tick())
script.Parent.MouseButton1Down:connect(function()
    local betmoney = tonumber(script.Parent.Parent.TextBox.Text)
    local playermoney = tonumber(game.Players.LocalPlayer.leaderstats.Money.Value)
    if betmoney > playermoney then
        print("lolno")
        script.Parent.Text = ("Error!")
        wait(1)
        script.Parent.Text = ("Bet")
    else
        if betmoney > 0 then
            script.Parent.Text = "Betting..."
local profit = 0
a = math.random(math.random(20)) 
for k = 1,a do
            local profit = (math.random(100) > 50) --// If the random number is more than 50, true. Otherwise, false.
end
            print(profit)
            if profit then --// If profit == true,
                game.Players.LocalPlayer.leaderstats.Money.Value = playermoney + betmoney
                script.Parent.Parent.Parent:Destroy()
            else --// Otherwise..
                game.Players.LocalPlayer.leaderstats.Money.Value = playermoney - betmoney
                script.Parent.Parent.Parent:Destroy()
            end
        else
            print("lolno")
            script.Parent.Text = ("Error!")
            wait(1)
            script.Parent.Text = ("Bet")
        end
    end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.