Problem with getting studs between two characters

So I am working on a sword fighting game and right now I’m trying to make a script when you kill someone it fires all the clients with a gui showing the player’s name and the studs between the kill, but for some reason the script doesnt want to work past the line of code where it find the studs between the players. Can anyone help me with it?


if Hum.Health <= 0 then	
		local plr = game.Players:GetPlayerFromCharacter(char)
		Character:FindFirstChild('Humanoid').Health = 100
		
		local humrp1 = char:FindFirstChild('HumanoidRootPart') --Enemy Character
		local humrp2 = Character:FindFirstChild('HumanoidRootPart') -- Your Character
		
		local Studs = math.round((humrp1 - humrp2).Magnitude)  -- Line of code that finds the studs
		
		print(Studs)
		
		local Player1 = Player.Name --Your Player
		local Player2 = plr.Name -- Enemy Player
		
		local RP = game:GetService('ReplicatedStorage')
		local Event = RP.Remotes:FindFirstChild('KillStud')
		Event:FireAllClients(Studs ,Player1, Player2)

I believe you’re only just referencing the Instances of the hurmp variables, when you should be getting the position instead? Try this:

		local Studs = math.round((humrp1.Position - humrp2.Position).Magnitude)  -- Line of code that finds the studs

I tried your version as well, but it still didn’t work

Could you try implementing a couple checks to see if everything works properly?

if Hum.Health <= 0 then	
		local plr = game.Players:GetPlayerFromCharacter(char)
		Character:FindFirstChild('Humanoid').Health = 100
		
		local humrp1 = char:FindFirstChild('HumanoidRootPart') --Enemy Character
		local humrp2 = Character:FindFirstChild('HumanoidRootPart') -- Your Character
		
        print(humrp1)
        print(humrp2)

		local Studs = math.round((humrp1.Position - humrp2.Position).Magnitude)  -- Line of code that finds the studs
		
		print(Studs)
		
		local Player1 = Player.Name --Your Player
		local Player2 = plr.Name -- Enemy Player
		
		local RP = game:GetService('ReplicatedStorage')
		local Event = RP.Remotes:FindFirstChild('KillStud')
		Event:FireAllClients(Studs ,Player1, Player2)

I tried your version to check where the problem is, and i think its from the humrp part, because it doesnt want to print out


 print(humrp1)
  print(humrp2)

Are you getting any errors when it tries to print those? Do they print out anything, even if it’s nil?

The issue’s probably something relevant to getting your plr & Character variables then :thinking: Can you check to make sure that both of them are valid & accessible to the script?

1 Like

it doesnt print anything, and i also get no errors when killing someone

Could it be that that if statement is never being entered? Put a print statement after the if Hum.Health <= 0 then line, if that also doesn’t print, then something else going on and we have to see the rest of your code

okay so i found the problem, it was that the Player.Name wasn’t valid

1 Like

okay so i found the problem, it was that the Player.Name wasn’t valid, Thanks a lot for helping tho!

1 Like