Ive only tried using health, but I find it annoying when the damage/damageui pops up. I want it to make a bubble/protection bubble around the player, just like spawn protection in games! Is there a way to not use
math.huge
math.floor
Do I need to access the humanoid for this? I tried looking through the humanoid properties, just health and maxHealth.
Please and thank you!
do
script.Parent.Touched.Connect(function(hit) if hit.Parent.Humanoid.Health <= 100 then hit.Parent.Humanoid.Health = 100
If you are making a safe zone, then perhaps Region3? Here is a script I just wrote. I wasn't in studio, so feel free to test it. The general idea is here, so have a go.
Before damaging the player, you can check if they are in the region3. Example
We are going to have a singular function to handle all of the damage. This makes it so we only need to write the region3 check once.
local replicatedStorage = game:GetService("ReplicatedStorage") local remoteEvent = replicatedStorage:WaitForChild("RemoteEvent") --Region3 Safezone local min = part.Position - (0.5 * part.Size) local max = part.Position + (0.5 * part.Size) local region = Region3.new(min, max) --Global function to handle the damage local function damageTarget(humanoid, enemy, amount) if humanoid == nil then return end if enemy == nil then return end local partsInRegion3 = workspace:FindPartsInRegion3(region) local found = false for _, parts in pairs(partsInRegion3) do if parts.Parent == enemy then found = true break end end) if found then return end --If within safe area then won't damage. humanoid:TakeDamage(amount) --if not in safe area, will damage end --Character Attack RemoteEvent.OnServerEvent:Connect(function(player) local character = player.Character local projectile = Instance.new("Part") projectile.Size = Vector3.new(2, 2, 2) projectile.CanCollide = false projectile.BrickColor = BrickColor.new("New yeller") projectile.CFrame = character.HumanoidRootPart.CFrame local newVelocity = Instance.new("BodyVelocity") newVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge) newVelocity.Velocity = (projectile.CFrame.lookVector * 50) newVelocity.Parent = projectile projectile.Parent = workspace local hitCooldown = {} projectile.Touched:Connect(function(hit) if hit:IsDescendantOf(character) then return end if hit.Parent:FindFirstChildOfClass("Humanoid") then if hitCooldown[hit.Parent] == nil then hitCooldown[hit.Parent] = true local enemy = hit.Parent local humanoid = enemy:FindFirstChildOfClass("Humanoid") damageTarget(humanoid, character, 25) --calling function end end end) game:GetService("Debris"):AddItem(projectile, 4) end)
For more information, check here for region3 https://developer.roblox.com/en-us/api-reference/function/WorldRoot/FindPartsInRegion3