local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local BuyButton = script.Parent.Buy
BuyButton.MouseButton1Click:Connect(function()
print("BUY BUTTON HAS BEEN CLICKED")
end)
I don’t understand why it’s not working my localscript is in a ScreenGui, my buttons seems to be active I don’t know if it’s the nesting of multiple layout of buttons
There isn’t a lot more information that you’ve provided us since the script is doing what it’s exactly doing; The BuyButton Event is just detecting when the Button is being pressed to run that print statement & that’s the end of the function
What are you wanting to do after clicking the button?
Make it a one-and-done event?
Make it have the ability to purchase said “thing” multiple times?
If you’re choosing 1 of those 2, you need to first check for conditional statements (Mainly server-sided) for buying that said “thing” in the game, and next change properties according to the local GUI (Changing Button + Text Color after purchase, displaying result of purchase, etc)
You have to finish off the rest on what you’d wanna accomplish with said Event (After clicking the button), if you’d like to take some suggestions you can add another IntValue that’ll display the game’s custom currency that it uses where you have your ExpPlayer script to create the leaderstats
I’d also recommend looking more into how RemoteEvents + RemoteFunctions works if you want to securely check your conditional statements via replication
-- Your LocalScript
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local RemoteFunction = RS:WaitForChild("RemoteFunction") -- You can name this to whatever you want
local LocalPlayer = Players.LocalPlayer
local BuyButton = script.Parent.Buy
local CostAmount = 0 -- Change this to however much it costs
BuyButton.MouseButton1Click:Connect(function()
local Result = RemoteFunction:InvokeServer(CostAmount)
print("BUY BUTTON HAS BEEN CLICKED")
if Result == "Success" then
print("Worked!")
elseif Result == "Not Enough"
print("Not Enough Currency!")
elseif Result "Failure" then
warn("Something weird happened!")
end
end)
-- Different Script
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local RemoteFunction = RS:WaitForChild("RemoteFunction") -- You can name this to whatever you want
local function Purchase(Plr, CostAmount)
local leaderstats = Plr:FindFirstChild("leaderstats")
if not leaderstats then return end
local Currency = leaderstats:WaitForChild("IntValueHere")
local CostRequirement = Currency.Value >= CostAmount
if CostRequirement == true then
Currency.Value -= CostAmount
return "Success"
elseif CostRequirement == false then
return "Not Enough"
else
return "Failure"
end
end
RemoteFunction.OnServerInvoke = Purchase
I mostly figured it might not be possible because the straight-forward implementation of a button input would be checking if the user clicked within the bounds of the active button. In addition to this, the buttons would be presumably checked parent-to-child, so the parent button would always take priority. It does work this way in other frameworks (HTML I think? I’m not really sure where I got it from).
Well anyway, I said it’s a bad idea because I also consider this to be bad UI design. I can’t think of a situation where nested buttons are needed or would look better / be more flexible than a different design. Do you have any examples where using nested buttons is a good design choice? This is another reason why I thought it might not be allowed