Ad
Log in to vote
0

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?

0
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
0
Answered by 8 months ago

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

local wall = script.Parent

game.Players.PlayerAdded:Connect(function(player)
    if player then
        wall.CanCollide = false
    else
        wall.CanCollide = true
    end
end)

Hope this works for you!

0
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
0
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
Ad

Answer this question