I’m trying to make a shop Gui where the player clicks the buy button and it takes their coins in turn for some spins.
This is the code that I used.
local player = game.Players.LocalPlayer -- The player
local coins = player:WaitForChild("CoinsNum") -- IntValue for the # of coins they have
local spins = player:WaitForChild("SpinsNum") --IntValue for the # of spins they have
local buyButton = script.Parent -- The actual buy button
local cost = script.Parent.Parent.Cost -- The cost button
buyButton.MouseButton1Click:Connect(function() -- When the player clicks the buy button
local ex = string.lower(tostring(cost.Text)) -- Detects the text of the cost button
if ex:find("Cost: 10") then -- If the text is ("blank") then do whatever next
if coins.Value >= 10 then -- If the players CoinsValue is Greater Than or Equal To 10 then
spins.Value = spins.Value + 1 -- Give the player 1 spin
coins.Value = coins.Value - 10 -- Take away 10 Coins
else print("Not enough money!") -- If they don't have enough then print this
end
elseif ex:find("Cost: 100") then
if coins.Value >= 100 then
spins.Value = spins.Value + 10
coins.Value = coins.Value - 100
else print("Not enough money!")
end
elseif ex:find("Cost: 250") then
if coins.Value >= 250 then
spins.Value = spins.Value + 25
coins.Value = coins.Value - 250
else print("Not enough money!")
end
elseif ex:find("Cost: 500") then
if coins.Value >= 500 then
spins.Value = spins.Value + 50
coins.Value = coins.Value - 500
else print("Not enough money!")
end
elseif ex:find("Cost: 1000") then
if coins.Value >= 1000 then
spins.Value = spins.Value + 100
coins.Value = coins.Value - 1000
else print("Not enough money!")
end
elseif ex:find("Cost: 2500") then
if coins.Value >= 2500 then
spins.Value = spins.Value + 250
coins.Value = coins.Value - 2500
else print("Not enough money!")
end
else print("what are u trying to buy it aint even detect it lol") -- If none of those texts are on the cost button then print this
end
end)
To avoid using multiple buy buttons for every single thing the player can buy I thought I’d use one, that’s why I detect if the cost text is equal to a specific text.
Whenever I actually test it out it always prints the “what are you even trying to buy” and I don’t know why.
Maybe I missed something or maybe I messed something up but any help would be greatly appreciated!