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”.
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)
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
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)
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)
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…
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)