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

I try to take 5 health from player every 2 seconds but kills character instantly Help?

Asked by 5 years ago
wait (1)
local character = game.Players.LocalPlayer.Character

character.Humanoid.Health = 1
local Message = Instance.new("BillboardGui",character)
local text = Instance.new("TextLabel",Message)
text.Text = "Life Leech"
text.Size = UDim2.new({0, 200},{0, 50})
text.BackgroundTransparency = 1
text.TextScaled = true
Message.Adornee = character.Head
Message.StudsOffset = Vector3.new(0,1.5,0)
text.TextColor3 = Color3.new(85,0,0)
text.TextStrokeColor3 = Color3.new(255,0,0)
text.TextStrokeTransparency = 0.4





--Sword
local sword = Instance.new("Part",character)
sword.Size = Vector3.new(1,5,1)
local swordmesh = Instance.new("SpecialMesh",sword)
swordmesh.TextureId = "http://www.roblox.com/asset/?id=262695937"
swordmesh.MeshId = "http://www.roblox.com/asset/?id=130101214"
swordmesh.Scale = Vector3.new(1,1,1)
local weld = Instance.new("Weld",character)
weld.Part1 = character["Right Arm"] 
weld.Part0 = sword
weld.C0 = CFrame.new(0.1,-2.8,0) * CFrame.Angles(2,0,0)
--Sword

--Fightevent
local Mouse = game.Players.LocalPlayer:GetMouse()
Mouse.Button1Down:Connect(function()
local p = character.Torso["Right Shoulder"]
sword.Touched:connect(function(hit)
        local b = hit.Parent:FindFirstChild("Humanoid")
        if b ~= nil then
        b:TakeDamage(5)
character.Humanoid.Health = character.Humanoid.Health + b.Health
    end
end)


for i = 1,10 do
p.C1 = p.C1:lerp(p.C1 * CFrame.Angles(0,0,math.rad(45)),0.8)
wait ()
end
end)
while true do
    character.Humanoid:TakeDamage(5)
    wait (2)
end

The lines where damage happens is at the end and at line 41 Can you tell me why the player gets instantly killed instead of 5 health being taken away

1 answer

Log in to vote
1
Answered by
zuup123 99
5 years ago

Add a cooldown to sword.Touched. When you touch a sword it will give you damage but it calls everytime you touch it.

Make it like this:

local debounce = false

sword.Touched:connect(function(hit)
    if debounce == false then
    debounce = true
        local b = hit.Parent:FindFirstChild("Humanoid")
        if b ~= nil then
        b:TakeDamage(5)
character.Humanoid.Health = character.Humanoid.Health + b.Health
wait(1) --cooldown here
debounce = false
    end
end)
0
I mean i am making a life leech script the sword is working how i want but the player who is in the possession of the sword Is being Life leeched (5 health drained every 2 seconds.)) antoniorigo4 117 — 5y
0
But still dude The sword part was fixed so thanks. antoniorigo4 117 — 5y
0
Oops i put humanoid.health = 1 i wonder how did i even type it there. antoniorigo4 117 — 5y
Ad

Answer this question