I have a laying animation that plays whenever someone toggles it but there’s an issue where players are still able to sit down in chairs even while the animation is playing. The laying animation changes the players jump power to 0 so they can’t exit a seat while the animation is toggled on. At the same time, there’s a check to see if a players current state is Seated and if it is they can’t toggle the animation on/off meaning they’re stuck. I need to prevent a player from being able to sit down while an animation is active.
local layToggle = false
UserInputService.InputBegan:Connect (function(key)
if key.KeyCode == Enum.KeyCode.V then
local currentState = Humanoid:GetState()
if layToggle == false and currentState ~= Enum.HumanoidStateType.Seated then
Character.Humanoid.WalkSpeed = 8
Character.Humanoid.JumpPower = 0
layToggle = true
Track:Play()
local DefaultFoV = 70
local Properties = {FieldOfView = DefaultFoV - 10}
local Info = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local Tween = game:GetService("TweenService"):Create(game.Workspace.CurrentCamera, Info, Properties)
Tween:Play()
else
if currentState ~= Enum.HumanoidStateType.Seated then
Character.Humanoid.WalkSpeed = 16
Character.Humanoid.JumpPower = 50
Track:Stop()
layToggle = false
local DefaultFoV = 60
local Properties = {FieldOfView = DefaultFoV + 10}
local Info = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local Tween = game:GetService("TweenService"):Create(game.Workspace.CurrentCamera, Info, Properties)
Tween:Play()
end
end
end
end)
What do you mean by they can still sit in a seat. Sorry if this sounds weird, but if it is a laying animation I dont think the player should be able to move, hence setting walkspeed to 0.
You could check if the player is currently seated, and if they are kick them out of the chair, turn their state to standing or whatever you need, then play the animation normally.
It’s more of like an army crawl, they can still move around at slow speeds. I have certain seats in the game that you don’t have an ability to get out of the seat.
You can make a variable inside the player and if the animation is playing, that variable will be false and the player may not sit, when the animation stops, make the variable true. With AnimationTrack:Stopped()
To add on, if the variable is equal to true and the player is sitting in the chair while the animation is playing, you can kick them out of the chair using Humanoid:ChangeState()