Error: Argument 1 missing or nil
Stack Begin
Script 'Workspace.Sell Model.Sell.Part.Script', Line 16
Stack End
local Part = script.Parent local plr = game.Players.LocalPlayer local ID = 7697627 Part.Touched:Connect(function(HIT) local H = HIT.Parent:FindFirstChild("Humanoid") if H then local player = game.Players:GetPlayerFromCharacter(HIT.Parent) if player then local leaderstats = player:WaitForChild("leaderstats") local Currency = leaderstats.Coins local Selling = leaderstats.Clicks if Selling.Value > 0 then Currency.Value = Currency.Value + Selling.Value *1 Selling.Value = 0 if game:GetService("MarketplaceService"):PlayerOwnsAsset(plr, ID) then Currency.Value = Currency.Value + Selling.Value *2 script.Parent.Coins:Play() end end end end end)
If we read the error message carefully, we'll see that the game is complaining because the first value given to the function at line 16 is nil
. In other words your variable plr
is nil. plr
becomes nil because you are trying to get the localplayer in normal script.
If i understand your code correctly, you want to check if the player who touched the badge owns a specific gamepass. If that's the case, then you don't want to use the plr
variable at all, instead use the already declared variable player
(at line 8) to get the user id.
-- replace line 16 with this instead: local userId = game.Players[player.Name].userId if game:GetService("MarketplaceService"):PlayerOwnsAsset(userId, ID) then
local Part = script.Parent local plr = game.Players.LocalPlayer local ID = 7697627 Part.Touched:Connect(function(HIT) local H = HIT.Parent:FindFirstChild("Humanoid") if H then local player = game.Players:GetPlayerFromCharacter(HIT.Parent) if player then local leaderstats = player:WaitForChild("leaderstats") local Currency = leaderstats.Coins local Selling = leaderstats.Clicks if Selling.Value > 0 then Currency.Value = Currency.Value + Selling.Value *1 Selling.Value = 0 if game:GetService("MarketplaceService"):PlayerOwnsAsset(plr.userId, ID) then Currency.Value = Currency.Value + Selling.Value *2 script.Parent.Coins:Play() end end end end end)
Lol you see people struggle with this all the time, it's just strange that marketplace service requires a userId instead of a player object so it confuses people :)