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

The Barrier does damage, but it insta kills even if i set the damage to 10??

Asked by 6 years ago
Edited 6 years ago
 I tried to make the barrier destroy after it did the damage but it didnt work

its in line 37 - 42

Here is the script:

local Tool = script.Parent


Tool.RemoteEvent.OnServerEvent:Connect(function(Player, Debounce)
local Character = Player.Character
local hum = Character.Humanoid
Debounce = true
local Barrier = Instance.new("Part")
Barrier.BrickColor = BrickColor.new("Lime green")
Barrier.Material = "Neon"
Barrier.Transparency = 0.25
Barrier.Anchored = false
Barrier.Size = Vector3.new(8,13,1)
Barrier.Shape = Enum.PartType.Block
Barrier.Locked = true
Barrier.CanCollide = false
Barrier.CFrame = Character.HumanoidRootPart.CFrame
Barrier.Parent = Character
local bv = Instance.new("BodyVelocity")
 bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = Character.HumanoidRootPart.CFrame.lookVector * 25
bv.Parent = Barrier












Barrier.Touched:Connect(function(hit)
local ehum = hit.Parent:findFirstChild("Humanoid") or           hit.Parent.Parent:findFirstChild("Humanoid")
 if ehum and ehum ~= hum then
 ehum:TakeDamage(10)
if ehum:TakeDamage(10)then
wait()
Barrier:Destroy()
end


end 
end)
0
debounce the touched event mattchew1010 396 — 6y
0
how? SplendidKyle567 8 — 6y
0
why is huge whitespace TheLionLiar 39 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

This could also be because it is hitting multiple parts of the game character, as a typical R15 character has 16 parts, it essentially does 160 damage, you can prevent this with a table of things it already hit, like StickMasterLuke did in his Mad Bloxxer tutorials.

local lastclick = tick()
local Tool = script.Parent
local hitHumanoids = {}

Tool.RemoteEvent.OnServerEvent:Connect(function(Player)
    local Character = Player.Character
    local hum = Character.Humanoid
    local Barrier = Instance.new("Part")
    Barrier.BrickColor = BrickColor.new("Lime green")
    Barrier.Material = "Neon"
    Barrier.Transparency = 0.25
    Barrier.Anchored = false
    Barrier.Size = Vector3.new(8,13,1)
    Barrier.Shape = Enum.PartType.Block
    Barrier.Locked = true
    Barrier.CanCollide = false
    Barrier.CFrame = Character.HumanoidRootPart.CFrame
    Barrier.Parent = Character
    local bv = Instance.new("BodyVelocity")
     bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
    bv.Velocity = Character.HumanoidRootPart.CFrame.lookVector * 25
    bv.Parent = Barrier

    Barrier.Touched:Connect(function(hit)
        if hit and hit.Parent and game.Players:GetPlayerFromCharacter(hit.Parent)  and not hit:isDescendantOf(Character) then
            local targethum = hit.Parent:FindFirstChild("Humanoid")
            if not hitHumanoids[targethum] then
                targethum:TakeDamage(10)
                hitHumanoids[targethum] = true --can be anything besides false or nil 
            end
        end
    end)
end)

Tool.Activated:Connect(function()
    hitHumanoids = {} --resets hitHumanoids when the tool is clicked
end)

This essentially makes a table of the humanoids hit/damaged, and checks if a humanoid that has been hit had been hit before, then if it didnt, it gets damaged and added to the table that is hitHumanoids

0
it doesnt work SplendidKyle567 8 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Simply use a cooldown or so called debounce into it. Here's an example:

--Script inside a part for example

local cooldown = false
script.Parent.Touched:connect(function(hit)
if not cooldown and hit.Parent:FindFirstChild("Humanoid")  then 
--If "cooldown" is "false" and it's a player then..
hit.Parent.Humanoid:TakeDamage(10)
cooldown = true
wait(5) --Wait 5 seconds before it deals damage again
cooldown = false --Since "cooldown" is "false" again, the barrier will now deal damage again!
end
end)
0
You can change the time of cooldown to whatever you please. Forgot to mention wilsonsilva007 373 — 6y
0
tab this correctly Vulkarin 581 — 6y
0
and connect is deprecated User#24403 69 — 6y
0
but i dont wnat to injure myself... SplendidKyle567 8 — 6y
0
If you don't want to injure ur self at line 06 change to "if not cooldown and hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= "YOURUSERNAMEHERE" then wilsonsilva007 373 — 6y

Answer this question