I'm trying to make realistic bed that when a player touches it a sleeping animation plays but they can still move even tho the player is doing an animation and when the player gets off the bed the animation stops playing
local part = script.Parent --part the script is inside of
local sleepanim = part.sleepanimation --the sleeping animation in the part
local touched = false
part.Touched:Connect(function(hit)
local humanoid = hit.Parent.Humanoid
if humanoid then
touched = true
elseif not humanoid then
touched = false
end
end)
part.Touched:Connect(function(hit)
local humanoid = hit.parent.Humanoid
local anim = humanoid:LoadAnimation(sleepanim)
if humanoid and touched == true then
anim:Play()
elseif not humanoid and not touched == true then
anim:Stop()
end
I have no idea how the script above doesn't work so I need help

4 comments
"I wouldn't suggest using the touched function sense it won't trigger until its being touched" ?? sorry to tell u mate but that's exactly what I'm trying to do i even made it clear in the question description
don't gemme wrong i appreciate u trying to help but there's just one vital thing missing from this script and that is ... it doesn't work
Did you cover the bed the part, and it should work if the player enters inside the part. That's how Region3 work.
And you first question, the Touched event will trigger if the player is on the bed, but the touched event won't trigger at all, when the player leaves the bed.