Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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?

1 comment

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

1 answer

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!

2 comments

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?

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

This discussion is preserved as it was. New answers, comments, and votes are closed.