10:53:43.668 Workspace.Base.Buttons.Claim this castle!.ClaimButtonScript:19: attempt to index nil with ‘UserId’ (x10)
In this script:
function steppedOn(part, player)
local hasPass = false
-- check if the player has the game pass
local success, message = pcall(function()
hasPass = Market:UserOwnsGamePassAsync(player.UserId, gamePassId1)
end)
-- stop function if something goes wrong
if not success then
warn(message)
return
end
-- if the player owns the game pass
if hasPass then
-- give plyr the trail
extrapartsAppear(player)
end
extrapartsAppear()
local character = part.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if player and player:FindFirstChild('ownsBase').Value == false then
script.Parent.Parent.Parent:FindFirstChild('Owner').Value = player
player:FindFirstChild('ownsBase').Value = true
player:FindFirstChild('Base').Value = script.Parent.Parent.Parent
script.Parent:Destroy()
end
end
button.Touched:Connect(steppedOn)
There’s more to the script, I’m only showing the part that needs work right now. The error is referring to line 5 with the player.UserId, gamePassid1.
Player is not a parameter of the Touched event. You have to get the player from the part that touched the block.
function steppedOn(part)
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if not player then return end
local hasPass = false
-- check if the player has the game pass
local success, message = pcall(function()
hasPass = Market:UserOwnsGamePassAsync(player.UserId, gamePassId1)
end)
-- stop function if something goes wrong
if not success then
warn(message)
return
end
-- if the player owns the game pass
if hasPass then
-- give plyr the trail
extrapartsAppear(player)
end
extrapartsAppear()
local character = part.Parent
local player = game.Players:GetPlayerFromCharacter(character)
if player and player:FindFirstChild('ownsBase').Value == false then
script.Parent.Parent.Parent:FindFirstChild('Owner').Value = player
player:FindFirstChild('ownsBase').Value = true
player:FindFirstChild('Base').Value = script.Parent.Parent.Parent
script.Parent:Destroy()
end
end
button.Touched:Connect(steppedOn)