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

I keep getting : bad argument #2 (string expected, got nil), any help?

Asked by 3 years ago
Edited 3 years ago

I keep getting this error : Players.SpoostyGuy.PlayerGui.ScreenGui.Shop.ImageButton.Script:5: bad argument #2 (string expected, got nil)

my code:




script.Parent.MouseButton1Click:Connect(function(plr) local playerTouch = game.Players[plr] if playerTouch.leaderstats.Coins.Value >= 60 then print("Bought!") playerTouch.leaderstats.Coins.Value = playerTouch.leaderstats.Coins.Value -60 else print("Not ENought Money!!") end end) pcall(function(msg) warn(msg) end)

Also, I am using a DataStore and the leaderboard does exist

Line 5 is fine but Line 2 is the problem

Help would be appreciated

0
Is this the full script? It doesn't seem like the error should be on line 5. If it is not what line is the error on the shortened version? blazar04 281 — 3y
0
and what is msg? blazar04 281 — 3y
0
it is a full version it is just line 2 SpoostyGuy 18 — 3y
0
msg is in a pcall just incase something errors with the script SpoostyGuy 18 — 3y
0
everything inside that pcall makes no sense to me Necro_las 412 — 3y

2 answers

Log in to vote
0
Answered by
blazar04 281 Moderation Voter
3 years ago
Edited 3 years ago

If is a LocalScript (it should be as you are manipulating UI), you could reference the player as local player = game.Players.LocalPlayer and fire a RemoteEvent to update leaderstats server-side.

1
Ok so Ill use an event to fire a server event using two variables(the cost and the player) and get the server event in server side by using a script and check if the player has enough money in the script and updating the players leader stats if they do SpoostyGuy 18 — 3y
0
Sounds good blazar04 281 — 3y
Ad
Log in to vote
0
Answered by
Necro_las 412 Moderation Voter
3 years ago

MouseButton1Click does not have the player as argument, it has nothing. You can check that in the Object Browser in studio inside "ImageButton"

Answer this question