Log in to vote

Why does my 1 lined code that should only let players through not work?

Asked by 8 months ago
Edited 8 months ago

I searched all over internet but can't find why my script doesn't work. I want to create a wall wich only Players can walk through and nothing else. so i created in starterplayerscripts a localscript with:

game.Workspace.noPassZombiewall.CanCollide = false

but if i try this out when i press run game in robloxstudio, npc's walk right through. if i try it in a server in roblox studio they dont walk through, but at some point still do. what am i doing wrong?

i tried & it works for me. did u misspell the wall name? make sure to anchor the wall & make sure to set CanCollide to true from the workspace itself ZeroToH3ro 82 — 8mo

1 answer

Log in to vote
Answered by 8 months ago

You can try to put a script inside of the wall, then use this code:

local wall = script.Parent

    if player then
        wall.CanCollide = false
        wall.CanCollide = true

Hope this works for you!

thanks for the fast respone! unfortunatly the NPC walks through the wall with this code, just like the player. even tho the cancollide is set to true before the game starts. what i also dont want is that if a player is touching a wall that the NPC can walk through wich i believe in this case is possible. do you know what i can do against that? joostie1 0 — 8mo
ur original code works for me, are u getting any errors in the output? if not then there's a problem with ur npcs, try and use other npcs to make sure the problem is with ur npcs ZeroToH3ro 82 — 8mo

Answer this question