So I’m making a singleplayer dice game right now, and I’m having some issues. Basically my objective is to detect if the player has rolled a 7 or 11 (win) 2, 3 or 12 (loss) or anything else (point).
It SOMEWHAT works, however sometimes it doesn’t deduct when it’s supposed to. Here is my code:
local Point = nil
local Bet
game.ReplicatedStorage.PlacedBet.OnServerEvent:Connect(function(player, placedBet)
Bet = placedBet
end)
game.ReplicatedStorage.FindResult.Event:Connect(function()
repeat
wait()
until _G.result1 ~= nil and _G.result2 ~= nil
local result = _G.result1 + _G.result2
if Point == nil then
if result == 7 or result == 11 then
local message = "You won by rolling a "..result.." on your first try!"
game.ReplicatedStorage.DisplayResult:FireAllClients(message)
for i, v in pairs(game.Players:GetPlayers()) do
v.leaderstats.Money.Value += Bet
end
result = nil
elseif result == 2 or result == 3 or result == 12 then
local message = "Unfortunately you lost by rolling a "..result.."."
game.ReplicatedStorage.DisplayResult:FireAllClients(message)
for i, v in pairs(game.Players:GetPlayers()) do
if v.leaderstats.Money.Value > 1 then
v.leaderstats.Money.Value -= Bet
end
end
result = nil
else
local message = "Great, you've got a point! Now roll a "..result.." to win! Avoid rolling a 7 though!"
game.ReplicatedStorage.DisplayResult:FireAllClients(message)
end
else
if result == Point then
local message = "You won by rolling your point!"
game.ReplicatedStorage.DisplayResult:FireAllClients(message)
for i, v in pairs(game.Players:GetPlayers()) do
v.leaderstats.Money.Value += Bet
end
result = nil
Point = nil
elseif result == 7 then
local message = "Unfortunately you lost by rolling a 7."
game.ReplicatedStorage.DisplayResult:FireAllClients(message)
for i, v in pairs(game.Players:GetPlayers()) do
if v.leaderstats.Money.Value > 1 then
v.leaderstats.Money.Value -= Bet
end
end
result = nil
Point = nil
end
end
end)
In this video, you can see it deducts for a 12 even though I have a point. Sometimes I might roll my point, and it doesn’t award me, and sometimes I might roll a 3 maybe and it doesn’t deduct anything (thank god lmao)
This might sound silly, but where are you setting the point variable? I can’t see in this code where point is being set to anything other than nil.
if Point == nil then
if result == 7 or result == 11 then
local message = "You won by rolling a "..result.." on your first try!"
game.ReplicatedStorage.DisplayResult:FireAllClients(message)
for i, v in pairs(game.Players:GetPlayers()) do
v.leaderstats.Money.Value += Bet
end
result = nil
elseif result == 2 or result == 3 or result == 12 then
local message = "Unfortunately you lost by rolling a "..result.."."
game.ReplicatedStorage.DisplayResult:FireAllClients(message)
for i, v in pairs(game.Players:GetPlayers()) do
if v.leaderstats.Money.Value > 1 then
v.leaderstats.Money.Value -= Bet
end
end
result = nil
else
local message = "Great, you've got a point! Now roll a "..result.." to win! Avoid rolling a 7 though!"
game.ReplicatedStorage.DisplayResult:FireAllClients(message)
end
else
In the last line, it says the player has a point, but nothing sets the point to anything other than nil from what I can see.
Same issue is still happening, my code looks like this:
Rolling a number that is not your point or a 7 breaks the game, and you can’t lose on your first roll.
local Point = nil
local Bet
game.ReplicatedStorage.PlacedBet.OnServerEvent:Connect(function(player, placedBet)
Bet = placedBet
end)
game.ReplicatedStorage.FindResult.Event:Connect(function()
repeat
wait()
until _G.result1 ~= nil and _G.result2 ~= nil
local result = _G.result1 + _G.result2
if Point == nil then
print({
result,
Point,
})
if result == 7 or result == 11 then
local message = "You won by rolling a "..result.." on your first try!"
game.ReplicatedStorage.DisplayResult:FireAllClients(message)
for i, v in pairs(game.Players:GetPlayers()) do
v.leaderstats.Money.Value += Bet
end
print("W")
elseif result == 2 or result == 3 or result == 12 then
local message = "Unfortunately you lost by rolling a "..result.."."
game.ReplicatedStorage.DisplayResult:FireAllClients(message)
for i, v in pairs(game.Players:GetPlayers()) do
if v.leaderstats.Money.Value > 1 then
v.leaderstats.Money.Value -= Bet
end
end
print("L")
else
local message = "Great, you've got a point! Now roll a "..result.." to win! Avoid rolling a 7 though!"
game.ReplicatedStorage.DisplayResult:FireAllClients(message)
Point = result
print("P")
end
else
print({
result,
Point,
})
if result == Point then
local message = "You won by rolling your point!"
game.ReplicatedStorage.DisplayResult:FireAllClients(message)
for i, v in pairs(game.Players:GetPlayers()) do
v.leaderstats.Money.Value += Bet
end
print("PW")
Point = nil
elseif result == 7 then
local message = "Unfortunately you lost by rolling a 7."
print(message)
game.ReplicatedStorage.DisplayResult:FireAllClients(message)
for i, v in pairs(game.Players:GetPlayers()) do
if v.leaderstats.Money.Value > 1 then
v.leaderstats.Money.Value -= Bet
end
end
print("PL")
Point = nil
elseif result ~= Point or result ~= 7 then
local message = "Keep rolling until you get a "..Point.."."
game.ReplicatedStorage.DisplayResult:FireAllClients(message)
end
end
end)