Problem with player death

Hello, So I got two scripts the first one makes it when the player touches a part play a animation.

The second one makes it that when they touch a part they die.

My problem is when they touch the part the don’t die I think its because in the first script it changes the name of the players humanoid but I need this to happen because if I didn’t change the name when the player touches the part it would always play the animation.

here are my scripts.

fisrt:

function onTouched(hit)
local human = hit.Parent:findFirstChild(“Humanoid”)
if human then
human.Name = “Glitch”
human.Parent.Head.face.Texture = “http://www.roblox.com/asset/?id=
script.Parent.Parent.Part.Shutter:Play()
local anim = human:LoadAnimation(script.Parent.Animation)
anim:Play()
human.WalkSpeed = 0
wait(3)
human.WalkSpeed = 16
end
end
script.Parent.Touched:connect(onTouched)

Second:

–Variables–
local Brick = script.Parent
–End–

–Script–
local function PlayerTouched(Part)
local Parent = Part.Parent
if game.Players:GetPlayerFromCharacter(Parent) then
if Parent.Humanoid.Name == “Glitch” then
Parent.Glitch.Health = 0
else
Parent.Humanoid.Health = 0
end
end
end

Brick.Touched:connect(PlayerTouched)

I just need it that when the player touches the kill part and the name of there humanoid is called glitch it still will damage them.

Issue is here:

if Parent.Humanoid.Name == “Glitch” then

This condition will never be met: Parent.Humanoid.Name will always be “Humanoid”. If you’re looking for “Parent.Glitch”, you’ll have to write “Parent.Glitch”.

For the second script, you’ll want to use :FindFirstChild() as so:

local function PlayerTouched(Part)
	local Parent = Part.Parent;
	if game.Players:GetPlayerFromCharacter(Parent) then
		if Parent:FindFirstChild("Glitch") then
			Parent.Glitch.Health = 0;
		elseif Parent:FindFirstChild("Humanoid") then
			Parent.Humanoid.Health = 0;
		end
	end
end

Brick.Touched:connect(PlayerTouched);

don’t change Humanoid and use debounce anim:Stop() or save it in another value in the part ?

2 Likes

I agree, this coding method is bound to cause problems down the line. Everything involving an animation unrelated to these 2 codes will need to be compatible with Glitch and Humanoid.

I concur, changing the name of Humanoid is not good practice.

1 Like