#Buy button won't work

1 messages · Page 1 of 1 (latest)

slow token
#

I am following this tutorial by BrawlDev:
https://www.youtube.com/watch?v=cwMMFL-ZtFY&list=PLQ1Qd31Hmi3WKkVHnadvhOOjz04AuMYAf&index=6

But my button does nothing when I click it! No errors appear either so I can't find any issues with it

DISCORD 📜
Join my Discord Community if you want scripting help, participate in events/challenges, and make friends!
https://discord.gg/WC6kPu5W5P

MEMBERSHIPS 🎁
Get Access To My Scripts + More Perks By Becoming a Channel Member! 👇
https://www.youtube.com/@BrawlDevRBLX/join

ADVANCED ROBLOX SCRIPTING SERIES 🔴
https://www.youtube.com/p...

▶ Play video
#

Here is my local script code (for the GUI):

#

local buyButtonFunction = game.ReplicatedStorage.BuyButton

local gui = script.Parent
local buyButton = gui.buyButton
local buyPrompt = gui.buyPrompt

buyButton.MouseButton1Click:Connect(function()
local purchaseSuccessful = buyButtonFunction:InvokeServer()

if purchaseSuccessful then 
    buyPrompt.text = "Bought"
    buyButton.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
    
else 
    buyPrompt.text = "Not Bought"
    buyButton.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
end

end)

#

and my leaderstats code:

#

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local greetPlayer = ReplicatedStorage.GreetPlayer
local announcement = ReplicatedStorage.Announcement
local giveCoins = ReplicatedStorage.GiveCoins

Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats" -- Changed to lowercase for Roblox leaderboard system
leaderstats.Parent = plr

local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Value = 50
coins.Parent = leaderstats


greetPlayer:FireClient(plr, "Hello! Welcome to the game! "..plr.Name)
task.wait(5)
greetPlayer:FireClient(plr, "Please join the group and like the game!")

end)

giveCoins.OnServerEvent:Connect(function(player, coinsamt)
local leaderstats = player:FindFirstChild("leaderstats") -- Changed to lowercase
if leaderstats then
local coins = leaderstats:FindFirstChild("Coins")
if coins then
print("button clicked, giving " .. tostring(coinsamt) .. " coins to " .. player.Name)
coins.Value = coins.Value + coinsamt
else
warn("Coins stat not found for player: " .. player.Name)
end
else
warn("leaderstats folder not found for player: " .. player.Name)
end
end)

task.wait(15)

announcement:FireAllClients() -- Corrected: FireAllClients is a method

local buyButtonFunction = game.ReplicatedStorage.BuyButton

buyButtonFunction.OnServerInvoke = function(plr)
local purchaseSuccessful = false

local leaderstats = plr.leaderstats
local coins = leaderstats.coins

if coins.value >= 50 then
    coins.value -= 50
    local purchaseSuccessful = true
end

end

full kestrel
#

this isnt the fixed script js easier for me to read alr

#

@slow token

#

is this a local or server script

#

oh god

#

If this is a local script:

.OnServerEvent doesnt work in local script
.FireClient doesnt work in local script

If this is a server script:

.MouseButton1Click doesnt work in server script

#

your button prolly doesnt do anything cause you wanna read clicks by the player from a server script

slow token
#

Its a local

faint pilotBOT
#

studio** You are now Level 1! **studio

full kestrel
#

oh god mb

#

wait

#

@slow token

#

y there

#
local buyButtonFunction = game.ReplicatedStorage.BuyButton

buyButtonFunction.OnServerInvoke = function(plr)
    local purchaseSuccessful = false

    local leaderstats = plr.leaderstats
    local coins = leaderstats.coins

    if coins.value >= 50 then
        coins.value -= 50
        local purchaseSuccessful = true
    end
end
#

your problem is in this code segment

#

@slow token

slow token
#

Yeah Im here

full kestrel
#

you are never returning true or false

slow token
#

How would I do that?

full kestrel
#
local buyButtonFunction = game.ReplicatedStorage.BuyButton

buyButtonFunction.OnServerInvoke = function(plr)
    local leaderstats = plr.leaderstats
    local coins = leaderstats.coins

    if coins.value >= 50 then
        coins.value -= 50
        return true
    end

    return false
end
slow token
#

Thanks!

#

and are there any replacements for .MouseButton1Click?

primal sparrow
slow token
#

kk

slow token
#

Yeah It still does nothing

#

Any other problems with the code?

#

lemme upload the code as 2 files to make it easier to see

#

Leaderstats:

#

Local script:

full kestrel
#

you still dont return anything in your server script i have legit sent you the code that would fix it

slow token
#

That fixed nothing

faint pilotBOT
#

studio** You are now Level 2! **studio

slow token
#

the button doesn't work with or without the return

slow token
#

returning this one value won't fix the whole button