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

How do I call a function upon the died event?

Asked by
Mystdar 352 Moderation Voter
10 years ago

I want to call this function upon the died event, you're on the Grey team if you're in the lobby. This is a local script in the StarterGUI

player = game.Players.LocalPlayer
playerName = ""..player.name
Character = game.Workspace:WaitForChild(playerName)
--[[Tables]]
local BrickColor = {BrickColor.new("White"), BrickColor.new("Black"), BrickColor.new("Medium stone grey")}

function Respawn()
    Lives = player.NoSave:WaitForChild("Lives")
    Playing = player.NoSave:WaitForChild("Playing")
    if player.TeamColor ~= BrickColor[3] then
        if Lives > 0 then
            Lives = Lives - 1
        elseif Lives == 0 then
            player.TeamColor = BrickColor[3]
        end
    elseif player.TeamColor == BrickColor[3] then return end
end

--[[I don't know how to do this last bit (calling)
This is what it normally is:
character:WaitForChild("Humanoid").Died:connect(function()
Would I do:]]
character:WaitForChild("Humanoid").Died:connect(Respawn()

Thanks

1 answer

Log in to vote
3
Answered by 10 years ago

You added a little extra () And you put character instead of Character. I also removed playerName because it wasn't needed. For example:

player = game.Players.LocalPlayer
Character = game.Workspace:WaitForChild(player.Name)
--[[Tables]]
local BrickColor = {BrickColor.new("White"), BrickColor.new("Black"), BrickColor.new("Medium stone grey")}

function Respawn()
    Lives = player.NoSave:WaitForChild("Lives")
    Playing = player.NoSave:WaitForChild("Playing")
    if player.TeamColor ~= BrickColor[3] then
        if Lives > 0 then
            Lives = Lives - 1
        elseif Lives == 0 then
            player.TeamColor = BrickColor[3]
        end
    elseif player.TeamColor == BrickColor[3] then return end
end

Character:WaitForChild("Humanoid").Died:connect(Respawn)

0
Well done Mystdar 352 — 10y
Ad

Answer this question