Greetings! I'm currently trying to make a sword fighting script. In this script what I have is an ObjectValue (Player1, Player2) which is Valued at each Player, I'm using a GetPlayerFromCharacter function to get each Player in Players and then it proceeds to check its health. What I would like to achieve would be constantly checking if any of the players health is at 0 and once one of them dies then it would print that the other player won and proceed to teleport the winning player but I'm getting the following error: Humanoid is not a valid member of Player "Players.Player1".
The script:
local Workspace =game:GetService("Workspace")
local Players = game:GetService("Players")
local SwordFight = Workspace.SwordFightArena.SwordFight
while true do
wait()
if SwordFight.Value == true then
local Player1 = game.Players:GetPlayerFromCharacter(Workspace.SwordFightArena.Players.Player1.Value)
local Player2 = game.Players:GetPlayerFromCharacter(Workspace.SwordFightArena.Players.Player2.Value)
if Player1.Character.Humanoid.Health == "0" then
print(Player2.." wins!")
wait()
Player2.Character.HumanoidRootPart.Position = Vector3.new(0, 0, 0)
elseif Player2.Character.Humanoid.Health == "0" then
print(Player1.." wins!")
wait()
Player1.Character.HumanoidRootPart.Position = Vector3.new(0, 0, 0)
end
end
end
Thanks in advance!

1 comment
Player.character.humanoid.health == 0