So, I'm trying to make a basic GUI script. When you click on the tool, a gui will pop up and if you click "yes" it will take away $5 of your money. If you click "no" the gui will close. The problem is: It's not that part of the script thats not working, its actually the clickdetector for the tool. The print statement after it doesn't run. Here is the script:
local player = game.Players.LocalPlayer local mainGUI = player.PlayerGui.BuyScreen local yes = mainGUI.Yes local no = mainGUI.No local info = mainGUI.Info local dollars = player.leaderstats.dollars local tool = script.Parent.Parent local price = 5 script.Parent.ClickDetector.MouseClick:Connect(function() print("Click!") mainGUI.Enabled = true info.Text = "Are you sure you want to buy "..tool.Name.." for $"..price.."?" yes.MouseButton1Click:Connect(function() if dollars.Value >= price then dollars.Value = dollars.Value - price local clonetool = tool:Clone() clonetool.Parent = player.Backpack local clonetool = tool:Clone() clonetool.Parent = player.StarterGear mainGUI.Enabled = false no.MouseButton1Click:Connect(function() mainGUI.Enabled = false end) end end) end)
Anyway, I would really appreciate it if you could help.
You cant have MouseClick in a localscript, that's why it isn't working. You must have it in a normal script.
To get the player that clicked, do this
script.Parent.ClickDetector.MouseClick:Connect(function(Player) -- Player is the player who clicked it
It appears you are attempting to use ClickDetectors for Gui Buttons. ClickDetectors are for detecting mouse clicks on 3d objects whilst a mouse button click detects clicks on 2d Ui objects.
Here's your script but modified:
local player = game.Players.LocalPlayer local mainGUI = player.PlayerGui.BuyScreen local yes = mainGUI.Yes local no = mainGUI.No local info = mainGUI.Info local dollars = player.leaderstats.dollars local tool = script.Parent.Parent local price = 5 function onClick() print("Click!") mainGUI.Enabled = true info.Text = "Are you sure you want to buy "..tool.Name.." for $"..price.."?" yes.MouseButton1Click:Connect(function() if dollars.Value >= price then dollars.Value = dollars.Value - price local clonetool = tool:Clone() clonetool.Parent = player.Backpack local clonetool = tool:Clone() clonetool.Parent = player.StarterGear mainGUI.Enabled = false end --Forgot to close off these function and if statements? end) no.MouseButton1Click:Connect(function() mainGUI.Enabled = false end) end end) script.Parent.MouseButton1Click:Connect(onClick) --MouseButton1Clicks detects left clicks on a 2d UI Object
I'm sorry if this was not what you were looking for.