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

Mistakes

Could anyone tell me If I got this right? Is there a more efficient way to do this?

game.Players.PlayerAdded:connect(function(player)
  player.Chatted:connect(function(msg)
    if msg == "Heal" then
      player.Character.Humanoid.Health = player.Character.Humanoid.MaxHealth
	  end
  end)
end)

game.Players.PlayerAdded:connect(function(player)
  player.Chatted:connect(function(msg)
    if msg == "Kill" then
      player.Character.Humanoid.Health = 0
	  end
  end)
end)

game.Players.PlayerAdded:connect(function(player)
  player.Chatted:connect(function(msg)
    if msg == "TeleportBack" then
      player.Character.Humanoid:MoveTo(CFrame.new(0,10,0))
	  end
  end)
end)

1 comment

1

Bad question title.

1 answer

✓ Accepted answer

Connecting three events can be alleviated by using elseif.

game.Players.PlayerAdded:connect(function(player)
	player.Chatted:connect(function(msg)
		if msg == "Heal" then
			player.Character.Humanoid.Health = player.Character.Humanoid.MaxHealth
		elseif msg == "Kill" then
			player.Character:WaitForChild("Humanoid").Health = 0
		elseif msg == "TeleportBack" then
			player.Character.Torso.CFrame = CFrame.new(0,10,0)
		end
	end)
end)

2 comments

0

ok thanks man. Was "player.Character.Humanoid:MoveTo(CFrame.new(0,10,0))" wrong?

0

player.Character.Humanoid:MoveTo(CFrame.new(0,10,0)) would make them walk to 0,10,0

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