Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

What is wrong with these lines of code [2 lines]?

W001: Unknown global 'player' was the error I got for the first 2 lines of code on this script.

game.Players.PlayerRemoving:connect(player) -- error here
    if player.Parent.Name==script.Parent.Owner.Value then -- error here
	script.Parent.Owner.Value = "Nobody"
	------------------------------------
	local gate = script.Parent.Gate
	if gate.Transparency ~= 0 then
		gate.Transparency = 0
		gate.CanCollide = true
	end
	------------------------------------
	local co = script.Parent.OwnershipDoor.ClaimOwnership
	co.BrickColor = BrickColor.new("Medium stone grey")
	co.Parent.OwnerName.SurfaceGui.Owner.Text = "Claim Ownership"
	co.Defender.Disabled = true
	co.Claim.Disabled = false

	script.Parent.Owner.Value = "Nobody"
	------------------------------------
	local gate = script.Parent.Gate
	if gate.Transparency ~= 0 then
		gate.Transparency = 0
		gate.CanCollide = true
	end
	------------------------------------
	local co = script.Parent.OwnershipDoor.ClaimOwnership
	co.BrickColor = BrickColor.new("Medium stone grey")
	co.Parent.OwnerName.SurfaceGui.Owner.Text = "Claim Ownership"
	co.Defender.Disabled = true
	co.Claim.Disabled = false
end

2 answers

Your forgot to make it a function.

game.Players.PlayerRemoving:connect(function(player) -- Edit here
    if player.Parent.Name==script.Parent.Owner.Value then
    script.Parent.Owner.Value = "Nobody"
    ------------------------------------
    local gate = script.Parent.Gate
    if gate.Transparency ~= 0 then
        gate.Transparency = 0
        gate.CanCollide = true
    end
    ------------------------------------
    local co = script.Parent.OwnershipDoor.ClaimOwnership
    co.BrickColor = BrickColor.new("Medium stone grey")
    co.Parent.OwnerName.SurfaceGui.Owner.Text = "Claim Ownership"
    co.Defender.Disabled = true
    co.Claim.Disabled = false

    script.Parent.Owner.Value = "Nobody"
    ------------------------------------
    local gate = script.Parent.Gate
    if gate.Transparency ~= 0 then
        gate.Transparency = 0
        gate.CanCollide = true
    end
    ------------------------------------
    local co = script.Parent.OwnershipDoor.ClaimOwnership
    co.BrickColor = BrickColor.new("Medium stone grey")
    co.Parent.OwnerName.SurfaceGui.Owner.Text = "Claim Ownership"
    co.Defender.Disabled = true
    co.Claim.Disabled = false
end) --Edit here (added a ")" )
game.Players.PlayerRemoving:connect(function(player) -- you need to add function <<
    if player.Name==script.Parent.Owner.Value -- I believe you dont need Parent because Player=game.players.RemovedPlayer
	then 
    script.Parent.Owner.Value = "Nobody" 
    ------------------------------------
    local gate = script.Parent.Gate
    if gate.Transparency ~= 0 then
        gate.Transparency = 0
        gate.CanCollide = true
    end
    ------------------------------------
    local co = script.Parent.OwnershipDoor.ClaimOwnership
    co.BrickColor = BrickColor.new("Medium stone grey")
    co.Parent.OwnerName.SurfaceGui.Owner.Text = "Claim Ownership"
    co.Defender.Disabled = true
    co.Claim.Disabled = false

    script.Parent.Owner.Value = "Nobody"
    ------------------------------------
    local gate = script.Parent.Gate
    if gate.Transparency ~= 0 then
        gate.Transparency = 0
        gate.CanCollide = true
    end
    ------------------------------------
    local co = script.Parent.OwnershipDoor.ClaimOwnership
    co.BrickColor = BrickColor.new("Medium stone grey")
    co.Parent.OwnerName.SurfaceGui.Owner.Text = "Claim Ownership"
    co.Defender.Disabled = true
    co.Claim.Disabled = false
end end)

This discussion is preserved as it was. New answers, comments, and votes are closed.