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

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

Asked by 2 years ago

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)
0
For line 10 and the rest, I'm pretty sure you have to do game.Players[player.Name] echobloxia 21 — 2y
0
correct me if I'm wrong though echobloxia 21 — 2y
0
@echobloxia Thanks, that is a problem. : ) kiki_2203 2 — 2y

2 answers

Log in to vote
0
Answered by 2 years ago

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

game.Players[player.Name]  -- instead of:
game.Players[player]
0
Thanks, that is a problem. kiki_2203 2 — 2y
0
no problem :) yayaheyman 90 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

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]

0
Thanks, that is a problem. kiki_2203 2 — 2y

Answer this question