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 danceAnimation[player] = humanoid:LoadAnimation(animation) end -- Bind setupPlayerData to PlayerAdded to call it when player joins. game.Players.PlayerAdded:connect(setupPlayerData) -- 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
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:
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
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
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" local danceAnimation[player] = humanoid:LoadAnimation(animation) 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
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?