local script to make / cancel coinflips
local CreateButton = script.Parent
local CancelButton = script.Parent.Parent.Cancel
local Amount = script.Parent.Parent.Amount
local CoinflipCreate = game:GetService("ReplicatedStorage").RemoteEvents.CoinflipCreate
local CoinflipCancel = game:GetService("ReplicatedStorage").RemoteEvents.CoinflipCancel
local Colors = script.Parent.Parent.Colors
local ColorsList = {
Purple = Colors.Purple.Activated;
Yellow = Colors.Yellow.Activated;
Green = Colors.Green.Activated;
Pink = Colors.Pink.Activated;
White = Colors.White.Activated;
Grey = Colors.Grey.Activated;
Red = Colors.Red.Activated;
Orange = Colors.Orange.Activated;
Blue = Colors.Blue.Activated;
}
local CoinflipAmounts = 0
local AmountText
Amount:GetPropertyChangedSignal("Text"):Connect(function()
if tonumber(Amount.Text) then
AmountText = tonumber(Amount.Text)
end
end)
local CoinflipColor
ColorsList.Purple:Connect(function()
CoinflipColor = Color3.fromRGB(170, 0, 255)
end)
ColorsList.Yellow:Connect(function()
CoinflipColor = Color3.fromRGB(255, 255, 0)
end)
ColorsList.Green:Connect(function()
CoinflipColor = Color3.fromRGB(85, 255, 0)
end)
ColorsList.Pink:Connect(function()
CoinflipColor = Color3.fromRGB(255, 0, 255)
end)
ColorsList.White:Connect(function()
CoinflipColor = Color3.fromRGB(255, 255, 255)
end)
ColorsList.Grey:Connect(function()
CoinflipColor = Color3.fromRGB(116, 116, 116)
end)
ColorsList.Red:Connect(function()
CoinflipColor = Color3.fromRGB(255, 0, 0)
end)
ColorsList.Orange:Connect(function()
CoinflipColor = Color3.fromRGB(255, 85, 0)
end)
ColorsList.Blue:Connect(function()
CoinflipColor = Color3.fromRGB(0, 0, 255)
end)
CreateButton.Activated:Connect(function()
CoinflipAmounts = CoinflipAmounts + 1
if CoinflipAmounts <= 1 then
CoinflipCreate:FireServer(tonumber(AmountText) , CoinflipColor)
end
end)
CancelButton.Activated:Connect(function()
if CoinflipAmounts >= 1 then
CoinflipAmounts = 0
CoinflipCancel:FireServer(tonumber(AmountText))
end
end)
server script that receives the remote events
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CoinflipCreate = ReplicatedStorage.RemoteEvents.CoinflipCreate
local CoinflipCancel = ReplicatedStorage.RemoteEvents.CoinflipCancel
local CoinflipBox = ReplicatedStorage.Gui.CoinflipBox
local PlayerText = CoinflipBox.Player
local CoinflipBoxClone
CoinflipCreate.OnServerEvent:Connect(function(player, Amount, CoinflipColor)
local Coinflips = player.PlayerGui.Coinflip.Frame.Coinflips
local Money = player.NonPvPStats.Money
if Money.Value >= tonumber(Amount) then
PlayerText.Text = player.Name
CoinflipBox.Text = "$"..Amount
CoinflipBox.BackgroundColor3 = (CoinflipColor) or Color3.fromRGB(255, 255, 255)
Money.Value = Money.Value - Amount
CoinflipBoxClone = CoinflipBox:Clone()
CoinflipBoxClone.Parent = Coinflips
else
print("to poor")
end
end)
CoinflipCancel.OnServerEvent:Connect(function(player, Amount)
local Coinflips = player.PlayerGui.Coinflip.Frame.Coinflips
local Money = player.NonPvPStats.Money
if CoinflipBoxClone then
Money.Value = Money.Value + Amount
CoinflipBoxClone:Destroy()
end
end)