New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
0

# Is there are way to completely freeze character and play an animation that can't be interrupted? [closed]

sleazel 679
6 months ago

I am working on a game, where players are climbing moving staircase and can cast spells (enchant) sections of it. One of the spells changes section into 1970's disco floor, and is supposed to freeze character and play a dance animation for 5 seconds. While I was able to freeze character, once a player tries to move or jump (which they usually do) the animation stops...

Since Create Stairs script is quite large I am posting just relevant section of it. (section fires when character touches the stairs's detection plate)

            --make player dance
if stairBase.StairsType.Value == "disco" and not playersWhoDanced[player] and spell ~= "destroy" then
print (player, " entered")
playersWhoDanced[player] = true
local dance = PlayerStatManager:letsDance(player)
--wait(1) -- let them climb a bit :)
local memory = character.Humanoid.WalkSpeed
character.Humanoid.WalkSpeed = 0
wait(1)
dance:Play()
wait(5)
dance:Stop()
character.Humanoid.WalkSpeed = memory
spawn(function()
wait(2) -- i want players to dance at least twice
playersWhoDanced[player] = false
end)
end



Relevant fragment of PlayerStatManager script:

-- Setup table that we will return to scripts that require the ModuleScript.
local PlayerStatManager = {}

local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?ID=507771019" -- dance animation

local danceAnimation ={}

function PlayerStatManager:letsDance(player)
return danceAnimation[player]
end

local function setupPlayerData(player)

local character = player.character or player.CharacterAdded:wait()
local humanoid = character:WaitForChild("Humanoid")
wait(3) -- lame I know, but i get strange errors otherwise

end

-- Bind setupPlayerData to PlayerAdded to call it when player joins.

-- Return the PlayerStatManager table to external scripts can access it.
return PlayerStatManager


Early Alpha can be accessed here. Just jump on the yellow beacon to cast disco spell.

https://www.roblox.com/games/2418401851

### Locked by User#24403

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

2
Edited 6 months ago

I can help later with a more detailed answer pertaining to the scripts you've placed here, but otherwise, the things you'd most likely need are:

1. Making the Player Immobile

Since you need to make the player able to also perform the animation, they need to remain un-anchored. As a result, as you did, you need to adjust the WalkSpeed of the player on the Server:

character.Humanoid.WalkSpeed = 0


Note: The AnimationTrack must be played in the same script it was added to the player

1. Making the Animation Continuous

The animation track has a property named "Looped" which if set to true, will make the animation continue playing until it has been stopped:

danceAnimation[player] = humanoid:LoadAnimation(animation)
danceAnimation[player].Looped = true

1. Removing the Jump Capabilities of the player

Humanoids have a property named "JumpPower" which will prevent jumping when set to 0

character.Humanoid.JumpPower = 0


Combined (Example w/ Debounce)

local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?ID=507771019"
danceAnimation[player].Looped = true

local debounce = true

function Spell()
if debounce == false then return end
debounce = false
character.Humanoid.WalkSpeed = 0
character.Humanoid.JumpPower = 0
danceAnimation[player]:Play()
wait(5)
character.Humanoid.WalkSpeed = 16 -- Default
character.Humanoid.JumpPower = 50 -- Default
danceAnimation[player]:Stop()
debounce = true
end


I used "character.Humanoid" since at some point not shown in the scripts you defined the character

0
Thank you kind sir, I will check this out now.  Edit: It works, thank you. I did have used JumpPower before, I just did not thought about it for some reason... Maybe because it is 2am in UK right now, so I guess that's enough for today. Much appreciated. sleazel 679 — 6mo