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.

10 comments
but why does the wiki says it should work? https://developer.roblox.com/en-us/api-reference/class/ClickDetector
Not sure, I tested it myself and local scripts didn't work with a Clickdetector
Same, localscripts didn't work when I tested them out. It seems my answer isn't what you're looking for
umm, it still didn't work. In fact, I put a print at the beginning of the script and IT DOESNT WORK, which means my script doesn't even run?
I even restarted studio with no luck. Im starting to think this may be a bug. Even completely removing the clickdetector function, it still doesn't show up. Prints dont work either.
this is 100% a bug. I literally deleted all the code from the script and did print("test") and it didnt come up
ClickDetectors do work with local scripts. It's the fact that you guys have your local scripts inside the workspace. Local scripts don't work inside workspace. It's not a bug. You can see where local scripts work here: https://developer.roblox.com/en-us/api-reference/class/LocalScript
The localscript is inside of a tool's handle, which IS allowed by the server.
wait... THE TOOL IS INSIDE OF THE WORKSPACE... im so sorry
yup, it works now