I am making a vip door for my game, Dayron Grill and was wondering if someone could help me figure this out.
local door = script.Parent
function open()
door.CanCollide = false
end
function close()
door.CanCollide = true
end
function get_player(part)
for _, player in ipairs(game.Players:GetPlayers()) do
if part:IsDescendantOf(player.Character)then
return player
end
end
end
door.Touched:Connect(function(part)
local player = get_player(part)
local character = player.Character
if not player then return end
end)
local allow = (
game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.userId, 12424604)
)
if allow then
open()
delay(1, close)
end
That is the script, the line it is giving me an error at is
You didn’t define the player correctly. When you use local this = that inside of a function you can only use that info in that function. You have your UserOwnsGamepassAsync outside of that function so the script doesn’t know what player is. You will need to put it all under one function of defining the player in a different way.
EDIT:
Also change userId to UserId like @Ze_tsu said.
Also, to resolve the question. The player variable is locally defined within the function, meaning it is not applied globally within the script. Therefore, you will want to define a global variable outside the function. This can be denoted as: player = nil at the start of the script, or whatever you prefer to name it.
local door = script.Parent
function open()
door.CanCollide = false
end
function close()
door.CanCollide = true
end
function get_player(part)
for _, player in ipairs(game.Players:GetPlayers()) do
if part:IsDescendantOf(player.Character)then
return player
end
end
end
door.Touched:Connect(function(part)
local player = get_player(part)
local character = player.Character
if not player then return end
local allow = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 12424604)
if allow then
open()
delay(1, close)
end
end)