Hello, so I wanted to make a part that lets npcs, like zombies go through but not the players, how can I make that?
Thanks for reading!
Hello, so I wanted to make a part that lets npcs, like zombies go through but not the players, how can I make that?
Thanks for reading!
This isn’t a request site, show us your code or attempt before making a request. If you had looked into this even a little bit you would’ve been able to do it easily. Even then, just set can collide to false on the part (in studio) and then make a local script that makes that part’s can collide to true. This makes players unable to touch it.
Here's some code that might help somewhat, it's not perfect but its a starting point. essentially the code checks if a humanoid touched the part and if so, it checks to see if that humanoid is a player by checking the players list and if a match is found it sets the collision on a door to be true.
If you want to test it just go into workspace and make a part called door and put this script inside it and tweak it to see what works for you
local door = workspace:WaitForChild("door)
door.Anchored = true
door.CanCollide = false
local players = game:GetService("Players")
local start_script = 0
players.PlayerAdded:Connect(function(player)
start_script = 1
end)
function check_if_allowed(otherTouch)
if start_script == 1 then
if otherTouch.Parent:FindFirstChildWhichIsA("Humanoid") then
local humanoid = otherTouch.Parent:FindFirstChild("Humanoid")
local h_name = tostring(humanoid.Parent)
if players:FindFirstChild(h_name) ~= nil then
door.CanCollide = true
wait(1)
door.CanCollide = false
end
end
end
end
door.Touched:Connect(check_if_allowed)
This discussion is preserved as it was. New answers, comments, and votes are closed.