So I'm making a shop. VERY basic one. Nothing to complicated, just so I can catch on. Here's what I have so far:
local Button = script.Parent
local gui = game.Workspace.surface.SurfaceGui.TextButton
local db = true
function check(hit)
local character = game.Players:GetPlayerFromCharacter(hit.Parent)
if character.leaderstats.Money.Value >= 5 then
character.leaderstats.Money.Value = character.leaderstats.Money.Value - 5
game.Lighting.Lantern:Clone().Parent = character.Backpack
else
db = false
gui.Text = "You need more money!"
wait(2)
gui.Text = " "
db = true
end
end
Button.MouseButton1Click:connect(check)
There's an error for some reason. I have no idea what I'm doing wrong. Everything works fine if I change it to a Touched event, but when I try to make a click event, nothing works. Any ideas? All help is appreciated!

9 comments
I'm confused. So, what's the solution? Where do I insert the "local plr = script.Parent.PARENTTOPLAYER
Well if this is in a SurfaceGui in workspace3 there is now way to get to know who clicked it, you will have to put the SurfaceGui in the player, handle the GUI locally and set the SurfaceGui's Adornee to the part in workspace instead. (yes it's confusing)
How can I put SurfaceGui into player? I'm sorry if I don't catch on, but I'm completely confused. The gui is in a brick. inside the gui there is a TextButton followed by a script. What does PARENTTOPLAYER mean?
(I have updated my answer)
Note that this answer is not FilteringEnabled compatible. Also, you don't use 'db' in your second script, you just assign to it.
Nope it's not FilteringEnabled compatible, I only changed it so that it should work (and didn't expect op to use FE)
Ok, I think I need to start a bit lower than this. It's too hard for me to understand. I'll come back to this later on, once I understand fundamental things. I'll accept your answer though, since I'll go back to this in the future. Thanks so much!
well did it work? >;3
I'm not sure. I haven't tried it. I just don't like inserting something I don't understand. That'd defeat the purpose of me learning. But, I'll get back to this for sure to see if it works.