Owner only path not working!

  1. What do you want to achieve?

A path that only owners can walk on and no one else!

  1. What is the issue?

The issue is everyone can walk on it!

  1. What solutions have you tried so far?

Finding a solution!

local players = {"xXLegandary_PlayzXx", "Official_ProGamerYT"}

game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:connect(function(chr)
		for i = 1, #players do
			if players[i] == plr.Name then 
				game.Workspace.Part.CanCollide = true
			else
				game.Workspace.Part.CanCollide = false
			end
		end
	end)
end)

Thank you in advance!

Hello, I see what you are trying to achieve here. For this you should be using for i,v in pairs(players)do and not for i =1, #players do. You are simply using the wrong loop. Also make sure its a local script because as you’ve said you only want owners to walk on the path so only the client should have the path cancollide set to true.

Now it won’t let the owners walk on it

local players = {"xXLegandary_PlayzXx", "Official_ProGamerYT"}

game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:connect(function(chr)
		for i,v in pairs(players) do
			if players[i] == plr.Name then 
				game.Workspace.Part.CanCollide = true
			else
				game.Workspace.Part.CanCollide = false
			end
		end
	end)
end)

Ok so, you can’t do this in a server script. So in a local script in StarterCharacterScripts try this:

local owners = {"xXLegandary_PlayzXx", "Official_ProGamerYT"}

local char = script.Parent
local player = game.Players:GetPlayerFromCharacter(char)

if table.find(owners, player.Name) ~= nil then
    game.Workspace.Part.CanCollide = true
else
    Game.Workspace.Part.CanCollids = false
end 
1 Like

Oh yes, I’ve completely forgot about table.find, you can use this instead of the loops, much better and clean. Good one domboss.

1 Like

Luau is not like other languages like C or Java in this manner. I don’t use this much but I am pretty sure that that i = 1 should be a i = 2 because there are two owners not one. In most other languages you would start at 0 but in roblox Luau you start at 1.

attempt to index nil with ‘Name’

Where did you put the script ?

Nevermind it is fixed I put it in the other one, Thank you!

No problem, mark the solution for future users that need help.