Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Find humanoid through a variable?

Okay, I am trying to get a players humanoid through a variable. Currently, I have;

Okay, so I removed all of the locals and had no luck.

There was no output, and all my script is

game.ServerStorage["Give Items"].Event:connect(function()
players = {}
Assassin = ""
Protector = ""

function GetPlayers()
for i,v in pairs(game.Players:GetChildren()) do
table.insert(players,v)
end
end

GetPlayers()

function SelectPlayer()
num = math.random(1,#players)
Assassin = players[num].Name
print('Assassin is: ' ..Assassin)
end

SelectPlayer()

function SelectPlayer2()
num = math.random(1,#players)
Protector = players[num].Name
print('Protector is: ' ..Protector)
end

SelectPlayer2()

if Assassin == Protector then
SelectPlayer2()
end

if Assassin == Protector then
SelectPlayer2()
end

if Assassin == Protector then
SelectPlayer2()
end

if Assassin == Protector then
SelectPlayer2()
end

if Assassin == Protector then
SelectPlayer2()
end


function Sword(player)
player = game.Players:FindFirstChild(player)
Sword = game.ServerStorage.MidnightSword:clone()
if player~= nil then
Sword.Parent=player.Backpack
end
end

function Bow(player)
player = game.Players:FindFirstChild(player)
Bow = game.ServerStorage.DynamicallyLitBow:clone()
if player~= nil then
Bow.Parent=player.Backpack
end
end

Sword(Assassin)
Bow(Protector)

end)

AssassinPlayer = game.Workspace:FindFirstChild(Assassin)

if AssassinPlayer.Humanoid.Health == 0 then
game.ServerStorage["Victims Won"]:Fire()
end

When I reset, it didn't fire the the event.

There are no errors in the script, either. Nothing in output; nothing. Why?

1 answer

Use the 'Died' Event. Link to: Died (Event) - Roblox Wiki

Line 1 of code edited.

AssassinPlayer = Assassin.Character

AssasinPlayer:WaitForChild("Humanoid").Died:connect(function()
game.ServerStorage["Victims Won"]:Fire()
end)

5 comments

0

It says "WaitForChild called on an Instance that is not a DataModel"

0

Change 'Game.Workspace:FindFirstChild(Assassin)' to 'Assassin.Character'

0

It still has that error.

0

Look at lines 1-18, your error is there.

0

Everything works perfectly. I can't find any errors there.

This discussion is preserved as it was. New answers, comments, and votes are closed.