Could anyone tell me If I got this right? Is there a more efficient way to do this?
01 | game.Players.PlayerAdded:connect( function (player) |
02 | player.Chatted:connect( function (msg) |
03 | if msg = = "Heal" then |
04 | player.Character.Humanoid.Health = player.Character.Humanoid.MaxHealth |
05 | end |
06 | end ) |
07 | end ) |
08 |
09 | game.Players.PlayerAdded:connect( function (player) |
10 | player.Chatted:connect( function (msg) |
11 | if msg = = "Kill" then |
12 | player.Character.Humanoid.Health = 0 |
13 | end |
14 | end ) |
15 | end ) |
Connecting three events can be alleviated by using elseif.
01 | game.Players.PlayerAdded:connect( function (player) |
02 | player.Chatted:connect( function (msg) |
03 | if msg = = "Heal" then |
04 | player.Character.Humanoid.Health = player.Character.Humanoid.MaxHealth |
05 | elseif msg = = "Kill" then |
06 | player.Character:WaitForChild( "Humanoid" ).Health = 0 |
07 | elseif msg = = "TeleportBack" then |
08 | player.Character.Torso.CFrame = CFrame.new( 0 , 10 , 0 ) |
09 | end |
10 | end ) |
11 | end ) |