How do I make an Owner Only Path

Bit of a simple question, but here it is none the less.

I’m making a simple Obby for my friend to try out, and I’m currently trying to make a path that’s only collidable for me. I can’t seem to figure out how to make it collidable for me and nobody else.

It’s pretty much a shortcut for the owner only. I call it a “Owner Only Path”.

4 Likes

Put a script inside the part and write the following:

script.Parent.Touched:Connect(function(Char)
	if game.Players:GetPlayerFromCharacter(Char).UserId == game.CreatorId then
		script.Parent.CanCollide = true
	else
		script.Parent.CanCollide = false
	end
end)
3 Likes

Sadly, this didn’t quite work, but Thank You for trying to help me. You responded very quick.

2 Likes

One second. let me test this myself.

1 Like

CanCollide = false means you can go thru
CanCollide = true means you can’t go thru

So it should be this instead:

script.Parent.Touched:Connect(function(HIT) -- when the part is touched
	local humanoid = HIT.Parent:FindFirstChild("Humanoid") -- searching for a humanoid 
	if humanoid then -- if a humanoid has been found then
		local player = game.Players:GetPlayerFromCharacter(HIT.Parent) -- get the player from the character

		if player.UserId == game.CreatorId then -- if the player is the owner then
			script.Parent.CanCollide = false -- can go thru part
		else
			script.Parent.CanCollide = true -- can't fo thru part
		end
	end
end)

I changed a couple other things aswell because else it wouldn’t work. Hope this helps :wink:

1 Like

It works, but this is memory reduced to the max:

script.Parent.Touched:Connect(function(Hit)
	if Hit and Hit.Parent:FindFirstChild("Humanoid") then
		local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
		if Player.UserId == game.CreatorId then
			script.Parent.CanCollide = false 
		else
			script.Parent.CanCollide = true
		end
	end
end)

@CRASHER_ZD111

1 Like

don’t try stealing the solution :confused:

I’m not, it’s memory reduced to the max. Your’s included a space which wont add memory by much, but it’s better this method.

Memory reduced to the max

script.Parent.Touched:Connect(function(Hit)
	if Hit and Hit.Parent:FindFirstChild("Humanoid") then
		if game.Players:GetPlayerFromCharacter(Hit.Parent).UserId == game.CreatorId then
			script.Parent.CanCollide = false 
		else
			script.Parent.CanCollide = true
		end
	end
end)

@CRASHER_ZD111

1 Like

By the way, spaces don’t do anything to the code. The game is not gonna die because i put everything step by step with explanation. You’re clearly trying something…

2 Likes

Thank You for this. I needed help really bad with this because I was so confused. :slight_smile:

Thank You as well, for helping me out.

Anytime! Have a nice day and have a fun time scripting!

Why did you steal @Youf_Dev’s code?

1 Like

While the solutions given do work they’re a little bit outdated, plus if someone walks right behind you they can also enter the “owner only” path.

a better way would be to create a new collision group for the path so that only you (the owner) can pass through.

open the “MODEL” tab > Click Advanced > Click collision groups > Now create 2 collision groups, one for normal players and another one for the owner, so in total you’ll have 3 (default, normal, owner).
Make sure that the new groups you created only collide with default and not each other.

Now select the part that’s blocking the owner path and change its collision group to “normal”, that way normal players cant pass through.

Now for the scripting, create a script in ServerScriptStorage. we’ll check if the owner joined so we can change their collision group.

game.Players.PlayerAdded:Connect(function(Player)
   Player.CharacterAdded:Connect(function(Character)
      if Player.Name == "Your Username Here" then
         for i,v in pairs(Character:GetChildren()) do
            if v:IsA("CharacterMesh") or v:IsA("Part") then
               v.CollisionGroup = "Owner"
            end
         end 
      else
            for i,v in pairs(Character:GetChildren()) do
               if v:IsA("CharacterMesh") or v:IsA("Part") then
                  v.CollisionGroup = "Normal"
               end
         end
      end
   end)
end)

hope that helps.
(sorry if the code looks weird I’m on mobile)

2 Likes

… just make the part cancollide off
and inside starterplayerscripts, add a local script:

if game.Players.LocalPlayer.UserId = game.CreatorId then
   path.to.path.CanCollide = true
end

script:Destroy()

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.