In Game Safe Haven

I have an alien in my game, but I want to have specific safe havens in game that will allow the player to be safe from the aliens. how would I do this??

1 Like

Have you attempted anything already?

To create safe zones, you need to either learn about .Touched events or getting distance between two parts (this article may help: Documentation - Roblox Creator Hub).

From there you can get your aliens to determine whether they should be ignoring a player or not; for example, if the player touches your safe zone (or is within 20 studs of the centre of the safe zone), add them to a table of players to ignore. If the player is in the ignore table, then your aliens should not target them.

2 Likes

I read the article, it doesnt make any sense. something that i tried is to make players pass through but aliens die, it didnt work. how would I do that?

1 Like

So assuming you have some invisible walls or a big invisible brick covering the area of the safe zone, you could check for when another part touches your invisible one, and if it does, check if the part belongs to a player or an alien. If it’s an alien, kill it.

The flow:

  1. Listen for a Part to touch your invisible part
  2. Check if Part’s Parent contains a Humanoid
  3. Check if Humanoid belongs to an Alien (maybe you named your Aliens “Alien,” or you’ve tagged them with CollectionService, or something)
  4. If it does, set the Humanoid.Health property to 0.
1 Like

I dont understand, I do have a block around the area, but idk where or how to do that

1 Like

If you’re new to scripting, you might benefit from a video tutorial. I found one on YouTube by @ItsGamerM8, who creates a part which sets your players health to math.huge (basically infinite health) while they’re in the safe zone. You could adapt this to check if the Humanoid belongs to an Alien and set its health to 0.

3 Likes

It’s hacky but can you just make a transparent part blocking the area where you don’t want aliens to go into? For all the non-aliens, you can client-sidedly remove the barrier so they can walk in.

local RegionPart = script.Parent
local Region = Region3.new(RegionPart.Position - (0.5 * RegionPart.Size), RegionPart.Position + (0.5 * RegionPart.Size))
RegionPart:Destroy()

local Watching = {}
while true do
	wait()
	Parts = workspace:FindPartsInRegion3WithIgnoreList(Region, {RegionPart}, math.huge)
	for i,v in pairs(Parts) do
		if v.Name ~= "HumanoidRootPart" then continue end
		local Player = game.Players:GetPlayerFromCharacter(v.Parent)
		if Player == nil then continue end
		local Character = v.Parent
		local Humanoid = Character["Humanoid"]
		if Humanoid ~= nil then
			Humanoid.MaxHealth = math.huge
			Humanoid.Health = Humanoid.MaxHealth
		end
		if not table.find(Watching, v) then
			Thread = coroutine.wrap(function()
				table.insert(Watching, v)
				while true do
					wait()
					local IsIn = workspace:FindPartsInRegion3WithWhiteList(Region, {v}, math.huge)
					if #IsIn == 0 then
						Humanoid.MaxHealth = 100
						Humanoid.Health = 100
						for x,c in pairs(Watching) do
							if c == v then
								table.remove(Watching, x)
							end
						end
						coroutine.yield(Thread)
					end
				end
			end)()
		end
	end
end

Here is my safezone script you can use as an example, just put it in a script underneath the safezone part.

This is actually what many people need,