As the title states, I'm receiving the output error:
Workspace.Part.SurfaceGui.Frame.Frame.Frame.TextButton.Scri:7: attempt to index local 'hit' (a nil value)
Whenever I use this script:
local price = 50 local light = game.Lighting.globaltyc local ipath = game.Workspace.Tycoon.Tycoon.InvInt script.Parent.MouseButton1Click:connect(function(hit) local user = game.Players:GetPlayerFromCharacter(hit.Parent) local stats = user:findFirstChild("leaderstats") player = game.Players[hit.Name] if game.Players:findFirstChild(hit.Name) == light.TycUser1.Value then ipath.Stone.Value = ipath.Stone.Value - 1 if stats ~= nil then local cash = stats:findFirstChild("Cash") cash.Value = cash.Value + price end end end)
A few important things about the script:
As always, any help is greatly appreciated, and thank you for reading!
The reason you're receiving this output is because the 'MouseButton1Click' event doesn't have any parameters which you can use.
The only way to get the player who clicked the button is by putting the SurfaceGui into each player's PlayerGui (via StarterGui), and treating it like an ordinary GUI. This means you'd get the player by parenting up to them, or in the case of a LocalScript you can use the 'LocalPlayer' property of the 'Players' service.