#My damage script is not functioning

1 messages · Page 1 of 1 (latest)

thorny lichen
#

I am making a zombie for my game and I want it to deal damage to the player, but it doesn't work

`local zombie = script.Parent
local workspace = game:GetService("Workspace")

local debounce = false
--Body parts of the zombie that can be used to damage the player
local LArm = zombie:WaitForChild("Left Arm")
local RArm = zombie:WaitForChild("Right Arm")
local Head = zombie:WaitForChild("Head")
local Torso = zombie:WaitForChild("Torso")
local humanoid = zombie:WaitForChild("Humanoid")
--finding the player
local vest = workspace:FindFirstChild("TacticalVest", true)
local Player = vest.Parent
local PlayerPos = Player.PrimaryPart.Position

humanoid.Touched:Connect(function(hit)
if hit.Parent == Player and not debounce then
debounce = true
Player.Humanoid.Health -= 20
print("Player hit")
print("Player health: " .. Player.Humanoid.Health)
wait(2)
debounce = false
end
end)`

The prints are not working so the touched event may not be firing.

jagged osprey
#

Bruv Ai

#

You shouldn't use if hit.parent == player

#

Cuz ur player isn't good

#

You should get do smth like this local part = script.Parent

part.Touched:Connect(function(hit)
local character = hit.Parent
local humanoid = character:FindFirstChild("Humanoid")

if humanoid then
    local player = game.Players:GetPlayerFromCharacter(character)
    if player then
        print(player.Name .. " touched the part!")
    end
end

end)

terse cairn
#

you cant touch a humanoid

#

do a HumanoidRootPart instead

random pasture
# thorny lichen I am making a zombie for my game and I want it to deal damage to the player, but...
local Players = game:GetService("Players");

local Zombie = script.Parent;

local ZombieHumanoid = Zombie:WaitForChild("Humanoid");

local debounce = false;

local Components = {
    Zombie.HumanoidRootPart,
    Zombie.Head,
    Zombie["Left Arm"],
    Zombie["Right Arm"],
    Zombie["Torso"],
};

local connections = {};

Zombie.Destroying:Once(function()
    for _,signal in pairs(connections) do
        signal:Disconnect();
        signal = nil;
    end
end)

for _,Part in pairs(Components) do
    
    local connection = Part.Touched:Connect(function(otherPart)
        
        if not debounce and otherPart.Parent:FindFirstChild("Humanoid") and Players:FindFirstChild(otherPart.Parent.Name) then
            
            local PlayerHumanoid = otherPart.Parent.Humanoid;
            
            if PlayerHumanoid.Health > 0 then
                
                debounce = true;

                PlayerHumanoid.Health -= 20;
                
                print("Player hit");
                
                print("Player health: " .. PlayerHumanoid.Health);

                task.wait(2);

                debounce = false;
                
            end
            
        end
        
    end)
    
    table.insert(connections,connection);
    
end```
tropic copperBOT
#

studio** You are now Level 1! **studio

thorny lichen
thorny lichen