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)
You used the variable "player", If this is a server script which I'm assuming it is you cant use "game.Players.LocalPlayer." In the code you tried to check and see if the player owned the gamepass, but since the SERVER SCRIPT cant use that. Therefore the variable "player" returns as nil, so you want to use the "plr" variable you made.
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(plr.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)