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

01player = game.Players.LocalPlayer
02playerName = ""..player.name
03Character = game.Workspace:WaitForChild(playerName)
04--[[Tables]]
05local BrickColor = {BrickColor.new("White"), BrickColor.new("Black"), BrickColor.new("Medium stone grey")}
06 
07function Respawn()
08    Lives = player.NoSave:WaitForChild("Lives")
09    Playing = player.NoSave:WaitForChild("Playing")
10    if player.TeamColor ~= BrickColor[3] then
11        if Lives > 0 then
12            Lives = Lives - 1
13        elseif Lives == 0 then
14            player.TeamColor = BrickColor[3]
15        end
View all 23 lines...

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:

01player = game.Players.LocalPlayer
02Character = game.Workspace:WaitForChild(player.Name)
03--[[Tables]]
04local BrickColor = {BrickColor.new("White"), BrickColor.new("Black"), BrickColor.new("Medium stone grey")}
05 
06function Respawn()
07    Lives = player.NoSave:WaitForChild("Lives")
08    Playing = player.NoSave:WaitForChild("Playing")
09    if player.TeamColor ~= BrickColor[3] then
10        if Lives > 0 then
11            Lives = Lives - 1
12        elseif Lives == 0 then
13            player.TeamColor = BrickColor[3]
14        end
15    elseif player.TeamColor == BrickColor[3] then return end
16end
17 
18Character:WaitForChild("Humanoid").Died:connect(Respawn)
0
Well done Mystdar 352 — 10y
Ad

Answer this question