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

Why appering this error "invalid argument #2 (string expected, got Instance)"?

Hello. This should be a script to purchase a particular item through ProximityPrompt. The problem arises when I have to add a "player" variable to the path to take a certain amount of money from the player. It needs to work in "Script", not "LocalScript", so I need something like *".LocalPlayer" *mode for "Script". I hope you understand the problem.

Error:

Workspace.ropebuy.Script:10: invalid argument #2 (string expected, got Instance). Error mark firsts "if" line as a problem.

Thanks.

local price = 200





script.Parent.item.ProximityPrompt.Triggered:Connect(function(player)
	
	
	if game.Players[player].Backpack.Money.Value >= price then
		
		game.Players[player].Backpack.Money.Value = game.Players[player].Backpack.Money.Value - price
		print("Buyed")
		
	end
	if game.Players[player].Backpack.Money.Value < price then
			
		script.Parent.error:Play()
		print("No money")
	end
	
end)

3 comments

0

For line 10 and the rest, I'm pretty sure you have to do game.Players[player.Name]

0

correct me if I'm wrong though

0

@echobloxia Thanks, that is a problem. : )

2 answers

✓ Accepted answer

I got this error the fix for it is the following:

game.Players[player.Name]  -- instead of:
game.Players[player]

2 comments

0

Thanks, that is a problem.

0

no problem :)

You're only getting the player's instance instead of the Name. Just like what @echobloxia said in the comments. Try doing game.Players[player.Name] instead of just game.Players[player]

1 comment

0

Thanks, that is a problem.

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