Hello, I am trying to fix an issue where the player buys a gamepass, and if purchased, a remote event is sent from the client to the server, however I get this error when trying to reference the player.
13:20:05.268 Error while checking if player has pass: ServerScriptService.RobuxShopHandler:8: attempt to index number with 'UserId' - Server - RobuxShopHandler:12
I have not found a solution so far, so I am asking here.
Here is what it looks like.
event.OnServerEvent:Connect(function(id, plr)
local hasPass = false
local success, message = pcall(function()
hasPass = gs:UserOwnsGamePassAsync(plr.UserId, id)
end)
if not success then
warn("Error while checking if player has pass: " .. tostring(message))
return
end
if hasPass then
if id == 16234236 then --Rainbow Trail
local trail = plr.Character.HumanoidRootPart:FindFirstChild("Trail")
if trail then
trail:Destroy()
end
local newtrail = game.ServerStorage.Trails.RainbowTrail:Clone()
newtrail.Parent = plr.Character.HumanoidRootPart
newtrail.Name = "Trail"
end
else
print("The user "..plr.Name.. " does not have the gamepass with the id "..id)
-- Player does NOT own the game pass; prompt them to purchase
end
The player instance who fired it is always given first, you also don’t need to give the player yourself as it does that for you, so just fire the id only
Did you also change the onServerEvent so plr is first and id is second? When I mentioned removing the player, I meant that only for the FireServer, as it’s unneeded, you still need plr for the first parameter of OnServerEvent, as that is given automatically