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

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

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

5 comments

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?

0

and what is msg?

0

it is a full version it is just line 2

0

msg is in a pcall just incase something errors with the script

0

everything inside that pcall makes no sense to me

2 answers

✓ Accepted answer

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.

2 comments

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

0

Sounds good

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

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