A path that only owners can walk on and no one else!
What is the issue?
The issue is everyone can walk on it!
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)
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.
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
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.