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
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.)
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?
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
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)