I'm trying to calculate a player's distance from a player they killed but it won't work, and when I check the error it only confuses me more.
Version 1
--###----------[[SERVICES]]----------###--
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--###----------[[KILLHANDLER]]----------###--
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character.Humanoid.Died:Connect(function()
print("Player Killed").
local tag = character.Humanoid:FindFirstChild("creator")
if tag ~= nil then
local Player = tag.value
local PlayerCharacter = Player.Character
local Distance = (PlayerCharacter.HumanoidRootPart.Position - character.HumanoidRootPart.Position).magnitude
print(Distance)
Player.leaderstats.Kills.Value += 1
ReplicatedStorage.EXPEvent:FireServer(player.Name)
print("Kill Added")
end
end)
end)
end)
Version 1 Error
HumanoidRootPart is not a valid member of Model "Workspace.Player2"
Version 2
--###----------[[SERVICES]]----------###--
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--###----------[[KILLHANDLER]]----------###--
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character.Humanoid.Died:Connect(function()
print("Player Killed")
local tag = character.Humanoid:FindFirstChild("creator")
if tag ~= nil then
local Killer = tag.Value
local Distance = player:DistanceFromCharacter(Killer.HumanoidRootPart.Position)
print(Distance)
Killer.leaderstats.Kills.Value += 1
ReplicatedStorage.EXPEvent:FireServer(player.Name)
print("Kill Added")
end
end)
end)
end)
WARNING
I should have said this beforehand but the entire code is inside a ServerScript that is inside of ServerScriptService

1 comment
I do know the error is from line 13, but when I put the ".magnitude" I still get the error from line 13(I should have said what line its from))