I’ve been working on a script that lets a player sit using a proximity prompt, but the issue is when the player stands up by pressing “space” it does not end the animation despite me having the “stop animation” sequence.
What did I do wrong? Any help is very much appreciated, thanks!
The script:
local prompt = script.Parent
local sit = prompt.Parent
local animation = script.Parent.Parent.sitanim
sit.Disabled = true
prompt.Triggered:Connect(function(player)
sit.Disabled = false
local char = workspace:WaitForChild(player.Name)
local hum = char.Humanoid
local loadAnim = hum.Animator:loadAnimation(animation)
loadAnim:play()
sit:Sit(hum)
prompt.Enabled = false
while sit.Occupant do
wait()
end
prompt.Enabled = true
sit.Disabled = true
animation:stop()
end)
I have some experience making games with features like that. I have code that I am using. I won’t write it myself.
But it works, hope it well help.
local seat = script.Parent
local sitanimation = seat.sitanimation
local sitAnim
seat.Changed:Connect(function(property)
if property ~= "Occupant" then return end
local occupant = seat.Occupant
if occupant then
local character = occupant.Parent
local humanoid = character.Humanoid
local player = game.Players:GetPlayerFromCharacter(character)
sitAnim = humanoid:LoadAnimation(sitanimation)
sitAnim:Play()
elseif sitAnim then
sitAnim:Stop()
end
end)