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?

01touched = false
02local function ontouch(hit)
03    if hit.Parent:FindFirstChild("Humanoid") then
04        local hum = hit.Parent:FindFirstChild("Humanoid")
05local players = game.Players:GetPlayers()
06for i = 1, #players do
07    wait()
08    local player = players[i]
09    repeat wait() until player.Character~= nil
10    if player.Character == hum.Parent then 
11    if not touched then
12        touched = true
13            if hit.Parent:FindFirstChild("Humanoid") ~= player.Character.Humanoid then
14        print(hit.Parent:FindFirstChild("Humanoid").Parent)
15        print("Bye")
View all 27 lines...

1 answer

Log in to vote
0
Answered by 5 years ago

I managed to fix it myself, lol.

01touched = false
02local function ontouch(hit)
03    if hit.Parent:FindFirstChild("Humanoid") then
04        local hum = hit.Parent:FindFirstChild("Humanoid")
05local players = game.Players:GetPlayers()
06for i = 1, #players do
07    wait()
08    local player = players[i]
09    repeat wait() until player.Character~= nil
10    if player.Character ~= hum.Parent then 
11    if not touched then
12        touched = true
13            if hit.Parent:FindFirstChild("Humanoid") ~= player.Character.Humanoid then
14                local hum = hit.Parent:FindFirstChild("Humanoid")
15                hum:TakeDamage(5)
View all 24 lines...
Ad

Answer this question