Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Script not detecting the amount of money players have?

Hi there! I've been working on some code for a backpack shop and it's not working. It's just not wanting to detect how much cash a player has. I got this output from the console

Argument 1 missing or nil

The code:


local playerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")

playerGui.BackpackShopGui.Frame.TwoHundred.MouseButton1Click:Connect(function(plr)
	if game.Players:FindFirstChild(plr.Name).leaderstats.Money.Value >= 500 then --// Where the error is
		plr.leaderstats.Money.Value = plr.leaderstats.Money.Value - 500
		plr.HiddenValues.BackpackCapacity.Value = 200
	end
end)

3 comments

0

Correction to the console output: attempt to index nil with 'Name'

0

that means that using find first child retuned nil, so you should try a different aproch

0

Remove the argument from mouse button function..

1 answer

✓ Accepted answer

There are no arguments passed into MouseButton1Click you need to use game.Players.LocalPlayer and if this is a ServerScript it needs to be a LocalScript since GUI manipulation is best done on the Client-Side

Also, If you are making a Shop Gui use Remotes (Most likely RemoteFunctions)

Don't Forget Basic Server Side Validation

5 comments

0

There ARE arguments being passed. I used 'plr' to collect the player data.

0

nah, there is no such thing as "plr" being passed when an mouse button down is called, and make sure that this script is parented to a button

0

and make sure that you use game:GetService("Players") for getting the gui, because I think that .Players doesent really work

0

There are NOT i think you are being confused with ClickDetectors.

0

Apologies, got confused. Thanks for the help.

This discussion is preserved as it was. New answers, comments, and votes are closed.