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

string expected got object while trying to clone into the player's backpack?

Asked by 4 years ago
Edited 4 years ago

OG script:

game.ReplicatedStorage.Purchase.OnServerEvent:Connect(function(Player, Price, Item)
    local new = game.ServerStorage[Item]:Clone()
    new.Parent = game.Players[Player].Backpack
end

Error: 13:21:12.619 - ServerScriptService.Leaderboard & Shop:3: bad argument #2 to '?' (string expected, got Object)


incapaxx answered in the comments, I didn't need to do game.Players[Player]

here's the fixed script

game.ReplicatedStorage.Purchase.OnServerEvent:Connect(function(Player, Price, Item)
    local new = game.ServerStorage[Item]:Clone()
    new.Parent = Player.Backpack
end
0
change game.Players[Player] to just Player. It's redundant to go backwards and index for the player when you have reference to it already. Also why are you letting the client determine the price? They can send a negative number to give themselves more money. User#24403 69 — 4y

Answer this question