You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
if player owns gamepass do code
What is the issue? Include screenshots / videos if possible!
attempt to index nil with UserId
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local gamepassId = 267444080 -- Gamepass ID
local service = game:GetService("MarketplaceService")
local players = game:GetService("Players")
local player = players:GetPlayerFromCharacter(plr)
if service:UserOwnsGamePassAsync(player.UserId, gamepassId) then
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
local timevalue = game.ReplicatedStorage.Time
local gameinprogress = game.ReplicatedStorage.GameInProgress
local lobbypart = workspace.Lobby
local gamepart = workspace.Game
local gamepassId = 267444080 -- Gamepass ID
local service = game:GetService("MarketplaceService")
local players = game:GetService("Players")
local intermissiontime = 10 --Change this to your intermission time in seconds
local gametime = 30 --Change this to your game time in seconds
while true do
timevalue.Value = intermissiontime
gameinprogress.Value = false
repeat timevalue.Value = timevalue.Value - 1
wait(1)
until timevalue.Value == 0
gameinprogress.Value = true
timevalue.Value = gametime
for _, plr in pairs(game.Players:GetChildren()) do
if plr.Character then
local player = players:GetPlayerFromCharacter(plr)
game.SoundService.Fight:Play()
--[[ this is the block I got an issue with
if service:UserOwnsGamePassAsync(player.UserId, gamepassId) then
plr.Character:MoveTo(gamepart.Position + Vector3.new(0,2,0))
game.ReplicatedStorage.Bombs["Elite Bomb"]:Clone().Parent = plr.Backpack
plr.leaderstats.Rounds.Value += 1
--]]
if plr.Name == "stcarrotboyguy" then
plr.Character:MoveTo(gamepart.Position + Vector3.new(0,2,0))
game.ReplicatedStorage.Bombs["Admin Bomb"]:Clone().Parent = plr.Backpack
plr.leaderstats.Rounds.Value += 1
else
plr.Character:MoveTo(gamepart.Position + Vector3.new(0,2,0))
game.ReplicatedStorage.Bombs.Bomb:Clone().Parent = plr.Backpack
plr.leaderstats.Rounds.Value += 1
end
end
end
repeat timevalue.Value = timevalue.Value - 1
wait(1)
until timevalue.Value == 0
gameinprogress.Value = false
timevalue.Value = intermissiontime
for _, plr in pairs(game.Players:GetChildren()) do
if plr.Character then
game.SoundService.Lobby:Play()
plr.Character:MoveTo(lobbypart.Position + Vector3.new(0,2,0))
plr.leaderstats.Kills.Value += plr.leaderstats.KillsRound.Value
plr.leaderstats.KillsRound.Value = 0
local status = Instance.new("IntValue")
status.Name = "value"
status.Value = 0
local inventory = plr.Backpack
for i,v in pairs(inventory:GetChildren()) do
if v:IsA("Tool") then
v:Destroy()
end
end
end
end
end
You can’t get player from a player object, it requires the character so do players:GetPlayerFromCharacter(plr.Character)
Or just do if service:UserOwnsGamePassAsync(plr.UserId, gamepassId) then, GetPlayerFromCharacter is completely useless in this case