Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Script not detecting the amount of money players have?

Asked by 4 years ago

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)
0
Correction to the console output: attempt to index nil with 'Name' ParticularlyPenguin 71 — 4y
0
that means that using find first child retuned nil, so you should try a different aproch marine5575 359 — 4y
0
Remove the argument from mouse button function.. SilentsReplacement 468 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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

0
There ARE arguments being passed. I used 'plr' to collect the player data. ParticularlyPenguin 71 — 4y
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 marine5575 359 — 4y
0
and make sure that you use game:GetService("Players") for getting the gui, because I think that .Players doesent really work marine5575 359 — 4y
0
There are NOT i think you are being confused with ClickDetectors. Luka_Gaming07 534 — 4y
0
Apologies, got confused. Thanks for the help. ParticularlyPenguin 71 — 4y
Ad

Answer this question