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

How do I tell my script that my characters model has been deleted?

I have a game that goes down to FallenPartsDestroyHeight but when that happens, it deletes my character, causing this script to cause an error:

wait(0.5)
while true do

for i, player in ipairs(game.Players:GetPlayers()) do
	if player.Character then
	player.leaderstats.Altitude.Value = player.Character.UpperTorso.Position.Y
	end
end

end



wait()
end

i've tried

 if not player.Character.UpperTorso.Position.Y <3 -40000 then

and

  if player.character.UpperTorso == nil

but they don't seem to work(maybe I just got them wrong...)

Edit: This works!

if player.Character:FindFirstChild("UpperTorso") then
	    player.leaderstats.Altitude.Value = player.Character.UpperTorso.Position.Y
		
	end

5 comments

1

Have you tried workspace.ChildRemoved?

0

no, I'll try it now

0

Because ChildRemoved returns the child being removed as an argument, you can connect the event to a function with an argument named child.

0

The problem is that as soon as the players charter is deleted, it fires up the error. How can I fix that?

0

Oh! I fixed it! Can you answer so I can accept your answer!

1 answer

✓ Accepted answer

accept this answer instead

so basically the HumanoidRootPart should be existing use that instead of the torso because it is the root part

if (player.Character and player.Character.PrimaryPart) then --// there is a primary part aka rootpart
	--// do ur codes
end
come at me kingdom5

2 comments

0

whats with the ( ) ?

0

getting into c++ tryna get in2 da habits ok bye my school is startin

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