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

Why is my code not damaging other players?

Asked by 5 years ago

This script is meant to damage everyone except the local player, but instead it does not damage anything. I already tried everything I could think of, anyone have an idea on what to do?

touched = false
local function ontouch(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local hum = hit.Parent:FindFirstChild("Humanoid")
local players = game.Players:GetPlayers()
for i = 1, #players do
    wait()
    local player = players[i]
    repeat wait() until player.Character~= nil
    if player.Character == hum.Parent then  
    if not touched then
        touched = true
            if hit.Parent:FindFirstChild("Humanoid") ~= player.Character.Humanoid then
        print(hit.Parent:FindFirstChild("Humanoid").Parent)
        print("Bye")
            hum:TakeDamage(5)
    end
    if hit.Parent:FindFirstChild("Humanoid") == player.Character.Humanoid then
        print("Hello")
        print(hit.Parent:FindFirstChild("Humanoid").Parent)
    end
    end
end
end
end
end
script.Parent.Touched:Connect(ontouch)

1 answer

Log in to vote
0
Answered by 5 years ago

I managed to fix it myself, lol.

touched = false
local function ontouch(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local hum = hit.Parent:FindFirstChild("Humanoid")
local players = game.Players:GetPlayers()
for i = 1, #players do
    wait()
    local player = players[i]
    repeat wait() until player.Character~= nil
    if player.Character ~= hum.Parent then  
    if not touched then
        touched = true
            if hit.Parent:FindFirstChild("Humanoid") ~= player.Character.Humanoid then 
                local hum = hit.Parent:FindFirstChild("Humanoid")
                hum:TakeDamage(5)
        print("Hello")
        print(hit.Parent:FindFirstChild("Humanoid").Parent)
    end
    end
end
end
end
end
script.Parent.Touched:Connect(ontouch)
Ad

Answer this question