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

My roblox script is acting very funny, and I can't seem to find an error, help?

Asked by 4 years ago

Basically making a tool that can ONLY damage "Enemy", works perfectly until the "Enemy"'s health goes to zero, and all the other Humanoid's health that are NOT "Enemy" is also set to zero, and the outpost doesn't say anything, maybe I'm doing something wrong?, not too sure.

local weapon = script.Parent
local damage = 25

weapon.Touched:Connect(function(TouchedPart)
    if TouchedPart ~= script.Parent.Parent.Parent then
        if TouchedPart.Parent:FindFirstChild("Enemy") then
            local Enemy = TouchedPart.Parent:FindFirstChild("Enemy")
            Enemy:takeDamage(25)
        end
    end
end)

Any help would be appreciated, thanks!

1 answer

Log in to vote
0
Answered by 4 years ago

If the Humanoid is Named Enemy then

local weapon = script.Parent
local damage = 25 

weapon.Touched:Connect(function(TouchedPart)
    if TouchedPart ~= script.Parent.Parent.Parent then
        if TouchedPart.Parent:FindFirstChild("Enemy") then
            local Enemy = TouchedPart.Parent:FindFirstChild("Enemy") --finds humanoid
            Enemy.Health = Enemy.Health - damage --takes away damage

        end
    end
end)

If the Humanoid is Called Humanoid

local weapon = script.Parent
local damage = 25  --the damage it will take away

weapon.Touched:Connect(function(TouchedPart)
    if TouchedPart ~= script.Parent.Parent.Parent then
        if TouchedPart.Parent:FindFirstChild("Enemy") then
            if TouchedPart.Parent:FindFirstChild("Humanoid") then --finds humanoid
            local Humanoid = TouchedPart.Parent:FindFirstChild("Humanoid") 
            Humanoid.Health = Humanoid.Health - damage --takes away damage

        end
    end
end)

You also had the local damage which wont change anything but now it will take away the damage you set at the top

0
Doesn't seem to work.. KevinsOOF 7 — 4y
0
is there any errors and is it in a serverscript? sturdy2004 110 — 4y
0
If there is no errors it might be because it cant find anything names Enemy? is there a part inside the model called enemy? sturdy2004 110 — 4y
Ad

Answer this question