I’m making a buy-gamepass UI button, but I get this error when trying to buy the gamepass:
07:32:46.871 UserId is not a valid member of InputObject "InputObject" - Client - LocalScript:16
local MPS = game:GetService("MarketplaceService")
local GPFrame = script.Parent.Parent
local GPId = GPFrame.GamepassId.Value
game:GetService("Players").PlayerAdded:Connect(function(player)
if MPS:UserOwnsGamePassAsync(player.UserId, GPId) then
GPFrame.OwnedLabel.Visible = true
else
if MPS:UserOwnsGamePassAsync(player.UserId, GPId) == false then
GPFrame.OwnedLabel.Visible = false
end
end
end)
script.Parent.Activated:Connect(function(player)
MPS:PromptGamePassPurchase(player.UserId, GPId)
end)
2 Likes
I don’t understand too much about gamepass, but try to use
game.Players.PlayerAdded:Connect(function(player)
-- Other code here
end)
instead of
game:GetService("Players").PlayerAdded:Connect(function(player)
-- Other code here
end)
That’s what I think not sure about it.
The code above is the same as the one below, so it should be fine either way.
1 Like
The parameter is the LocalPlayer not the player’s UserId
The issue is here, I don’t believe this returns a player instance, what type of script is this?
As a matter of fact, the one I use is more efficient than the one you provided. GetService
is essentially WaitForChild
but for services, if you just use a direct attribute assignment, you may call PlayerAdded
on nil, because Players
might not be a thing
Is the script inside of the UI?
This is a LocalScript, I read on the docs that I should use player
instead of player.UserId
, but I tried that and it didn’t work.
Wait if this is in a localscript, can’t you just do this?
script.Parent.Activated:Connect(function()
local plr = game.Players.LocalPlayer
MPS:PromptGamePassPurchase(plr, GPId)
end)
I was literally just about to come to terms with myself with that one.
1 Like
Haha it’s okay! Sometimes we don’t realise the answer until at a later time! As I would recommend changing
game:GetService("Players").PlayerAdded:Connect(function(player)
if MPS:UserOwnsGamePassAsync(player.UserId, GPId) then
GPFrame.OwnedLabel.Visible = true
else
if MPS:UserOwnsGamePassAsync(player.UserId, GPId) == false then
GPFrame.OwnedLabel.Visible = false
end
end
end)
since this is a localscript since this will not detect your player in time but it will detect other players. If you just want it to check if you own the gamepass, then jsut make it a single if statement without the event
If you have anymore issues don’t be afraid to make another post!
Thanks for the help peoples
local MPS = game:GetService("MarketplaceService")
local GPFrame = script.Parent.Parent
local GPId = GPFrame.GamepassId.Value
local player = game.Players.LocalPlayer
if MPS:UserOwnsGamePassAsync(player.UserId, GPId) then
GPFrame.OwnedLabel.Visible = true
else
GPFrame.OwnedLabel.Visible = MPS:UserOwnsGamePassAsync(player.UserId, GPId)
end
script.Parent.Activated:Connect(function()
MPS:PromptGamePassPurchase(player, GPId)
end)
1 Like