So i have mede a portal, when you touch it you got 1 stage completed and it need to give 60 points if player haves the gamepass, but i got wrong on something. The output says ServerScriptService.Script:13: attempt to index nil with 'UserId' There is my script:
local db = false --Adding a debounce
local MarketPlaceService = game:GetService("MarketplaceService")
local GamepassID = 24389862
local player = game.Players.LocalPlayer
local portal = workspace.FirstStage.FrostPartal.PortalPart --Defining the portal
portal.Touched:Connect(function(hit) --Touched function
if hit.Parent:FindFirstChild("Humanoid") and not db then --Checking if a player touched it and that debounce is false
db = true --Making debounce true
local plr = game.Players:GetPlayerFromCharacter(hit.Parent) --Getting the player that touched it
plr.leaderstats.Stages.Value = plr.leaderstats.Stages.Value + 1 --Adding value
if MarketPlaceService:UserOwnsGamePassAsync(player.UserId, GamepassID) then
plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 60
print("nice!")
else
plr.leaderstats.Points.Value = plr.leaderstats.Points.Value + 30
wait(10) --The cooldown for the debounce, you can make this as much as you want
db = false --Making debounce false
end
end
end)

2 comments
Is this code in a local script or a server script?
Nvm i fixed that