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

How do I detect a child object that is within another child object?

Asked by 6 years ago

All day I have been trying to fix this script, yet no success. My goal is to have the script detect an object within a Player's character and then act accordingly to said character being killed. The main issue seems to be detecting the object within the character. There are probably multiple reasons to why this script is not working, but I am not skilled enough yet to know what they may be.

The code:

dft = {}


function GetPlayers()
local c = game.Players:GetPlayers()
for i = 1, #c do 
table.insert(dft, c[i].Name) 
end 
end



local EnemyGUI = game.StarterGui:FindFirstChild("Enemy")

local Draw = game.StarterGui:FindFirstChild("All Losers")


function PresidentDeath()
    local thing = game.Players:FindFirstChild(dft["Character"]).President
    local president = thing.Parent
        president.Humanoid.Died:connect(function()
            local Humanoid = president:WaitForChild("Humanoid")
            if president.Humanoid:FindFirstChild("creator") ~= nil then -- If Humanoid was killed by another Player
                local Killer = Humanoid.creator.Value
                if Killer.TeamColor ~= president.Player.TeamColor or president.Humanoid.Health == 0   then
                    for i,v in pairs(game.Players:GetPlayers()) do
                        v.PlayerGui.Enemy.Frame.Visible = true
                    print("worked once")
                    end
                end
                end
            end)
    end 
while true do
wait(3)
PresidentDeath()
end

1 answer

Log in to vote
0
Answered by
Prestory 1395 Moderation Voter
6 years ago

You could use something called

GetDescendants()

Heres how you could learn how to use it:

https://wiki.roblox.com/index.php?title=API:Class/Instance/GetDescendants

Ad

Answer this question