Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
sleazel 1287 Moderation Voter
6 years 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)

01--make player dance
02if stairBase.StairsType.Value == "disco" and not playersWhoDanced[player] and spell ~= "destroy" then
03    print (player, " entered")
04    playersWhoDanced[player] = true
05    local dance = PlayerStatManager:letsDance(player)
06    --wait(1) -- let them climb a bit :)
07    local memory = character.Humanoid.WalkSpeed
08    character.Humanoid.WalkSpeed = 0
09    wait(1)
10    dance:Play()
11    wait(5)
12    dance:Stop()
13    character.Humanoid.WalkSpeed = memory
14    spawn(function()
15        wait(2) -- i want players to dance at least twice
16        playersWhoDanced[player] = false
17    end)
18end

Relevant fragment of PlayerStatManager script:

01-- Setup table that we will return to scripts that require the ModuleScript.
02local PlayerStatManager = {}
03 
04local animation = Instance.new("Animation")
05animation.AnimationId = "http://www.roblox.com/Asset?ID=507771019" -- dance animation
06 
07local danceAnimation ={}
08 
09 
10 
11function PlayerStatManager:letsDance(player)
12    return danceAnimation[player]
13end
14 
15local function setupPlayerData(player)
View all 29 lines...

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.

Why was this question closed?

1 answer

Log in to vote
2
Answered by 6 years ago
Edited 6 years 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:

1character.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:

1danceAnimation[player] = humanoid:LoadAnimation(animation)
2danceAnimation[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

1character.Humanoid.JumpPower = 0

Combined (Example w/ Debounce)

01local animation = Instance.new("Animation")
02animation.AnimationId = "http://www.roblox.com/Asset?ID=507771019"
03local danceAnimation[player] = humanoid:LoadAnimation(animation)
04danceAnimation[player].Looped = true
05 
06local debounce = true
07 
08function Spell()
09if debounce == false then return end
10debounce = false
11    character.Humanoid.WalkSpeed = 0
12    character.Humanoid.JumpPower = 0
13    danceAnimation[player]:Play()
14    wait(5)
15    character.Humanoid.WalkSpeed = 16 -- Default
16    character.Humanoid.JumpPower = 50 -- Default
17    danceAnimation[player]:Stop()
18debounce = true
19end

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 1287 — 6y
Ad