How do I make a safe point where you cannot get killed?

I suppose I could have been more clear in my original posting regarding how much the server handles then.

1 Like

This is a no no, using a zone as a part is not good. If a player is using other touched events inside the zone. Such as NPCs or general gameplay mechanics. That function will constantly be falsely fired. If the client has a slow PC, FPS takes a hit. If the server handles touch events, server performance hits. Also if you attempt to do anything with raycast or mouse.target. The big invisible zone literally breaks those abilities unless you add mouse.targetfilter. And any moving parts that use touch events will always have to check for the big safe zone part. Just causes redundancy, delay, and performance hit.

1 Like

Sadly in roblox there isn’t much clarity. Since a majority of devs still continue to rely on client sided stuff, and their game experience is negatively affected by that.

1 Like

I have a few questions.

  1. Are these 2 separate scripts?
  2. Where do they go?
  3. When you say add my damage function, I don’t exactly have one :flushed:

I don’t have any parts of a script for ot

1 Like

Just change humanoid health and maxhealth to inf and store the old health, and when the player leaves, set the maxhealth and health to the stored value then delete that value

1 Like

How do I do that?? Thanks for helping everyone by the way.

1 Like

Heres your questiosn answered in a weird order but to make more sense.

  1. They are a single script. Just the functions go outside of an event. just like where you call your local variables and stuff basically. At the very top of the script outside of any events or other functions. If you have multiple damaging scripts you could separate the functions and tables. And just remove the bottom portion, and turn it into a module script with a dictionary, so you can build onto it. But that’s a little more advanced

  2. That’s okay. Even if it’s a touch event. Consider that your damage event. Whether it’s a function you fire in case you have multiple weapons that do different damage. Or if you have a script for each item, or all items do damage the same. It would have an area where it minus health.

  3. Just where ever you put “Health = Health - Damage”
    You would replace it with this

if not checkSafeZones(player) then--checking if in safezone, returning false. checking for not=false
	Health = Health-Damage
end 

and outside the touchEvent or what ever event your using for damage. You put all of this

------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------
---------------------Insert all of this in script, but outside of damage event/function---------------------
------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------

local safeZones = {
--Set zone boundarie values from lowest to highest.
	zone1 = {
		XBoundaries = {-25,25},--XMin, XMax
		YBoundaries = {-math.huge, math.huge},--Covers complete Y axis. Change if you want. YMin,YMax
		ZBoundaries = {-25,25}--ZMin, ZMax
	}
	
} 

function checkSafeZones(player)
-----------------------------Is in bound local function, helps prevent long/nested if statement
	local function inBounds(value, boundariesTable)
		
		local valuemin, valuemax = table.unpack(boundariesTable)--Unpacking Current Zone Boudnaries
		
		if value >= valuemin and value <= valuemax then
			return true
		else
			return false
		end
	end
-----------------------------Checking bounds
	local Root = player.Character:FindFirstChild("HumanoidRootPart")
	if Root then--Make sure player has HumanoidRootPart to check position
		local PlayerPosition = Root.Position--Getting position
		local PlayerX, PlayerY, PlayerZ = PlayerPosition.X, PlayerPosition.Y, PlayerPosition.Z--Unpacking position
-----------------------------Running through all zones to check if player is in one
		for i,v in pairs(safeZones) do--Loops thru all zones
			local XBoundaries = v.XBoundaries
			local YBoundaries = v.YBoundaries
			local ZBoundaries = v.ZBoundaries
			
			if inBounds(PlayerX, XBoundaries) and inBounds(PlayerY, YBoundaries) and inBounds(PlayerZ, ZBoundaries) then--Checking if in the current zone
				return true--Is in zone retrun true and stop the function
			end
			
		end
-----------------------------Not in bounds
		return false--Returning false, if it reaches this point it means player isn't in safezone
	end
end
1 Like

Is there a way to code it to make the safe point a part, rather than the X,Y,Z?

1 Like

Read my reply above about doing this. Invisible safe parts get in the way of mouse.target unless you mouse.target.filter. But also touch events are extremely iffy. and any moving parts, let’s say ray cast to make bullet holes will also have to filter this invisible part. Also adds invisible triangles on the client-side, which still affects GPU performance slightly. But little stuff like this adds up, and that’s why optimizing a game is a pain, it’s about knocking down a million little things. Saves you the hassle by doing this earlier.

Also, you can enter more than one zone.

You can have as many as you want.

1 Like

also just make a part. you want area to cover. and since a parts position is at it’s center

to calculate the boundaries

xMin=Part.Position.X-(Part.Size.X/2)
xMax=Part.Position.X+(Part.Size.X/2)

Same would be with Y and Z axis just change the Axis

You can do this in the table if you want.

It would recommend not using the part though and only temporaly adding it to get the values you want.

1 Like

it works, but its not optimized

1 Like

This styling of comments looks off.

1 Like

Wdym. it works with the comments, test it. I did too.

1 Like

What he meant to say was your comments look bad!!!

1 Like

what about when the player is jumping?

1 Like

Check the distance on the Y axis

1 Like