So I wanna make like when player1 kills player2, player 1 gets full health if player 1 is low health
But it didn’t work out
How do i fix this problem?
player.CharacterAdded:Connect(function(character)
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
if humanoid.RigType == Enum.HumanoidRigType.R6 then
local clone = game.ServerStorage.ClassicSword:Clone()
clone.Parent = player.Character
end
end
player.Character.Humanoid.Died:Connect(function()
local tag = character.Humanoid:FindFirstChild("creator")
if tag ~= nil then
local Player = tag.Value
local HumanoidKill = Player:FindFirstChild("Humanoid")
if (HumanoidKill ~= nil) then
HumanoidKill.Health = HumanoidKill.MaxHealth
end
local expVal = 100
local exp = Player:WaitForChild("Exp")
exp.Value = exp.Value + expVal
end
end)
end)
end)```
local function getPlayerFromName(name) -- Function to get Player from string
for _, player in pairs(game:GetService("Players"):GetPlayers()) do -- loop over all players
-- if their name matches (case insensitive), return with that player:
if player.Name:lower() == name:lower() then
return player
end
end
-- if we reach the end of the for-loop, no player with that name was found
end
-- Your original code --
--local Player = tag.Value -- Replaced by:
local Player = getPlayerFromName(tag.Value)
print("Killed by; ", Player.Name)
Bumping this post up. Actually im trying to heal up the killer humanoid hp. Came back and I see I did very wrong.
Even though i don’t need this code. But ima fix it if anyone has the same problem like this.
player.CharacterAdded:Connect(function(character)
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
if humanoid.RigType == Enum.HumanoidRigType.R6 then
local clone = game.ServerStorage.ClassicSword:Clone()
clone.Parent = player.Character
end
end
player.Character.Humanoid.Died:Connect(function()
local tag = character.Humanoid:FindFirstChild("creator")
if tag ~= nil then
local Player = tag.Value
local HumanoidKill = Player.Character:FindFirstChild("Humanoid")
if (HumanoidKill ~= nil) then
HumanoidKill.Health = HumanoidKill.MaxHealth
end
local expVal = 100
local exp = Player:WaitForChild("Exp")
exp.Value = exp.Value + expVal
end
end)
end)
end)