Need Help with Making Character unable to jump and then kill

I am not a scripter, so i’ve been a little confused on how to do this, but basically i just want an animation to play when someone sits in a seat, but also so it makes them unable to jump out and then kills them after 6 seconds or so. here is the script im working with. The animation works when they sit down and everything, but i just need to figure out how to add the no jump and kill after 6 seconds to this script. And I only want these rules to apply to this specific seat, not all the seats in the game.

seat = script.Parent

function added(child)
if (child.className==“Weld”) then
human = child.part1.Parent:FindFirstChild(“Humanoid”)
if human ~= nil then
anim = human:LoadAnimation(seat.sitanim)
anim:Play()
end
end
end

function removed(child2)
if anim ~= nil then
anim:Stop()
anim:Remove()
end
end

seat.ChildAdded:connect(added)
seat.ChildRemoved:connect(removed)

Here’s an updated function added() to use instead. An explanation on how to do it is to set the player’s humanoid JumpPower property to 0, then use task.wait(6) to wait 6 seconds, then use human:TakeDamage(math.huge) to kill them.

function added(child)
	if (child.ClassName == "Weld") then
		
		local human = child.part1.Parent:FindFirstChild("Humanoid")
		
		if human ~= nil then
			anim = human:LoadAnimation(seat.sitanim)
			anim:Play()
			human.JumpPower = 0
			
			task.wait(6)
			
			human:TakeDamage(math.huge)
		end
	end
end

(If you are using JumpHeight instead, replace human.JumpPower to human.JumpHeight.)

2 Likes

Hey! Everything worked great but there was one issue i found, it works great the first time, and resets the person, but the next time that person tries it again, they never die and get stuck in the animation loop, do you know why that is?

That’s weird, as it works for me every time. May you share a video of the issue if possible?

Here! Watch 2024-06-03 11-25-46 | Streamable

Is the JumpPower property or the humanoid getting set to 0, or does that not change at all?

This is the full script

seat = script.Parent

function added(child)
if (child.ClassName == “Weld”) then

	local human = child.part1.Parent:FindFirstChild("Humanoid")

	if human ~= nil then
		anim = human:LoadAnimation(seat.sitanim)
		anim:Play()
		human.JumpHeight = 0
	

		task.wait(6)

		human:TakeDamage(math.huge)
	end
end

end

seat.ChildAdded:connect(added)
seat.ChildRemoved:connect(removed)

Try this script. Do exactly what you did in the video, and tell me if they both print on the second try:

local seat = script.Parent
local anim = nil

function added(child)
	if (child.ClassName == "Weld") then
		local human = child.Part1.Parent:FindFirstChild("Humanoid")

		if human ~= nil then
			local anim = human.Animator:LoadAnimation(seat.sitanim)
			anim:Play()
			human.JumpPower = 0
			
			print("JumpPower is set to 0!")

			task.wait(6)
			
			print("Killing Player...")

			human:TakeDamage(math.huge)
		end
	end
end


function removed(child2)
	if anim ~= nil then
		anim:Stop()
		anim:Remove()
	end
end

seat.DescendantAdded:connect(added)
seat.DescendantRemoving:connect(removed)

Okay so they both printed each time, even when it didnt kill me, buttt i think it might have been because of spawn protection maybe? I disabled it and i havent ran into the issue since!

Interesting! Apparently, TakeDamage() doesn’t work when you have spawn protection, as you mentioned. If you want to keep spawn protection, here’s an updated script, which should work even with spawn protection. The only thing I changed was setting the humanoid’s health to 0, which is an effective workaround to the issue.

local seat = script.Parent
local anim = nil

function added(child)
	if (child.ClassName == "Weld") then
		local human = child.Part1.Parent:FindFirstChild("Humanoid")

		if human ~= nil then
			local anim = human.Animator:LoadAnimation(seat.sitanim)
			anim:Play()
			human.JumpPower = 0

			task.wait(6)

			human.Health = 0
		end
	end
end


function removed(child2)
	if anim ~= nil then
		anim:Stop()
		anim:Remove()
	end
end

seat.DescendantAdded:connect(added)
seat.DescendantRemoving:connect(removed)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.