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

PlayerOwnsAsset problem, arugment missing or nil. How do I fix it?

Asked by 4 years ago

I have a issue with PlayerOwnsAsset. They "if game:GetService" line says Arugment Missing or Nil.

plr = game.Players:FindFirstChild(script.Parent.Parent.Parent.Selecteduser.User.Text)
passId = 1761589018

script.Parent.MouseButton1Click:Connect(function()
    if game:GetService("MarketplaceService"):PlayerOwnsAsset(plr, passId) then
        script.Parent.Parent.Parent.Parent.BusinessAgree:TweenPosition(UDim2.new(.042,0,.352,0))
        script.Parent.Parent.Parent.Parent.BusinessAgree["Check-in"].TextLabel.Text = "The following player has Business, please press continue."
    else
        script.Parent.Parent.Parent.Parent.BusinessAgree:TweenPosition(UDim2.new(.042,0,.352,0))
        script.Parent.Parent.Parent.Parent.BusinessAgree["Check-in"].TextLabel.Text = "The following player does not have Business, this will automatically close now"
    end
end)
0
is you're gamepass a legacy game pass? if so, use GamePassService throwawayaccount2001 102 — 4y
0
Its a tshirt. DennisSense 23 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

The reason why it's erroring with Argument Missing or Nil is because you're defining the player wrong, and is not a safe way to define the player at all. Assuming this is a LocalScript, you would instead need to use game.Players.LocalPlayer.

Also, another thing that's wrong with your script is the HUGE amounts of script.Parent's, it's very unnecessary in my opinion and reduces readability by a lot, which is something programmers should generally keep in mind when making scripts. Assuming the code you're showing right now is the only code in your script, you can just move the LocalScript closer to the MainFrame or whatever is close to BusinessAgree to avoid the script.Parent.Parent, etc, or you can just use variables.

Lastly, use never forget to make your variables local.

So you could do this instead

local plr = game.Players.LocalPlayer
local passID = 1761589018
local button = button location --was script.Parent
local BusinessAgree = location

button.MouseButton1Click:Connect(function()
    if game:GetService("MarketplaceService"):PlayerOwnsAsset(plr, passId) then
        --code
    else
        --code
    end
end)
0
I didn't even notice this was a local script lel throwawayaccount2001 102 — 4y
0
We fixed it via discord! DennisSense 23 — 4y
0
GuiObjects should generally be eddited on the client, so that's how I assumed it was a LocalScript Godlydeathdragon 227 — 4y
Ad

Answer this question