Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can I make a safe zone without using maxHealth?

Asked by 4 years ago
Edited 4 years ago

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!

0
What weapons are you using? You can make them do 0 damage if the player is in the safe zone. srimmbow 241 — 4y
0
@srimmbow so im guessing a boolean value will be used for this, I'm just doing some preparing until I add my punch tool to my weight lifting game, I guess I could do that. Make a int value for the damage? alabamalover90001 2 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

do

script.Parent.Touched.Connect(function(hit)
if hit.Parent.Humanoid.Health <= 100 then
hit.Parent.Humanoid.Health = 100
0
add end because you didn't ended "if" ErktikyYT 89 — 4y
0
ok catsalt29 57 — 4y
Ad
Log in to vote
0
Answered by
Despayr 505 Moderation Voter
4 years ago

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

Answer this question