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

This Script is supposed to keep a NPC from leaving an area but it doesn't work what did i do wrong?

this is my script

local name = game.Workspace.NPCS.Meliodas.Name --The NPC humanoid is called zombie too

if name == ("Meliodas") then --Meliodas is the name of the NPC
	game.Workspace.MW.CanCollide = true -- MW is the wall 
end

2 comments

0

What?

0

is that the full script? Cuz I don't understand how that will keep an NPC from leaving a certain area, u could use a region3 if it's a cuboid.

1 answer

workspace.MW.Touched:Cinnect(function(hit)
     local hum = hit.Parent.Humanoid
     if hum then
          if hum.Parent.Name == "Meliodas" then
               workspace.MW.CanCollide = true
          else
               workspace.MW.CanCollide = false
          end
     end
end)

Put this ServerScript in the workspace

3 comments

0

May I ask why in workspace instead of server script service?

0

Typo on line 1, you wrote 'Cinnect'.

0

Because the script runs on items that are in the workspace. But i think you can put it inside the server script service too

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