but then how would i play each on animation
Animation1:Play()
this line wouldnt work anymore if i did that
but then how would i play each on animation
Animation1:Play()
this line wouldnt work anymore if i did that
since its a array it actually looks like
[1] = Player.Humanoid:LoadAnimation(script.Slices),
[2] = Player.Humanoid:LoadAnimation(script.Spin),
[3] = Player.Humanoid:LoadAnimation(script.BackFlipStab),
[4] = Player.Humanoid:LoadAnimation(script.DownSlice)
VS.
Animation1 = Player.Humanoid:LoadAnimation(script.Slices),
Animation2 = Player.Humanoid:LoadAnimation(script.Spin),
Animation3 = Player.Humanoid:LoadAnimation(script.BackFlipStab),
Animation4 = Player.Humanoid:LoadAnimation(script.DownSlice)
--so what animations[fly] does is searches through the table to find the value (or the thing on the right side) based on a random number 1-4 , my first result looks at the left side that isn't numbers and gets confused, so if the table looks like the top result when it searches through numbers it finds the number it equals and sets the animation to that. if you dont get what i mean look at https://developer.roblox.com/en-us/articles/Table
btw dont set the table to
[1] = Player.Humanoid:LoadAnimation(script.Slices),
[2] = Player.Humanoid:LoadAnimation(script.Spin),
[3] = Player.Humanoid:LoadAnimation(script.BackFlipStab),
[4] = Player.Humanoid:LoadAnimation(script.DownSlice)
its just an example of what it looks like when you print
Player.Humanoid:LoadAnimation(script.Slices),
Player.Humanoid:LoadAnimation(script.Spin),
Player.Humanoid:LoadAnimation(script.BackFlipStab),
Player.Humanoid:LoadAnimation(script.DownSlice)
This is a bit out of my league at the moment lol so is this the right thing to do/
-- idk what that wait is but use task.Wait if your going to use wait
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character
local Humanoid = Character.Humanoid
local animations = {
Player.Humanoid:LoadAnimation(script.Slices),
Player.Humanoid:LoadAnimation(script.Spin),
Player.Humanoid:LoadAnimation(script.BackFlipStab),
Player.Humanoid:LoadAnimation(script.DownSlice)
}
local canFly = true
local function giveAnimation()
local Fly = math.Random(1,5)
if canFly then
local animation = animations[fly]
canFly = false
animation:Play()
Humanoid.Walkspeed = 0
Humanoid.JumpPower= 0
task.Wait(0.5)
Humanoid.Walkspeed = 16 -- or whatever the orginal values are
Humanoid.JumpPower= 50
canFly = true
end
end
script.Parent.Parent.Activated:connect(giveAnimation)
I think that is right, I think I made tables seem way more complex than they are read this:
Hm…i must be doing something wrong because the animations won’t seem to play.
also (fly) generates an error. unknown global error
If you anchor any parts of the character model (especially HumanoidRootPart), your animations won’t play. I would suggest you to just set the walkspeed and jump power of the humanoid both to 0.
Anchor the HumanoidRootPart, this makes the character unable to move.
I found the solution. I just took my original script and added Humanoid.WalkSpeed and Humanoid.JumpPower. Thanks everybody the help i really appreciate it.
wait(3)
local Player = game.Players.LocalPlayer
local Humanoid = Player.Character.Humanoid -- Humanoid
Player = game.Players.LocalPlayer.Character
Animation1 = Player.Humanoid:LoadAnimation(script.Slices)
Animation2 = Player.Humanoid:LoadAnimation(script.Spin)
Animation3 = Player.Humanoid:LoadAnimation(script.BackFlipStab)
Animation4 = Player.Humanoid:LoadAnimation(script.DownSlice)
CanFly = true
script.Parent.Parent.Activated:connect(function()
local Fly = math.random(1,4)
if Fly == 1 and CanFly == true then
Humanoid.WalkSpeed = 0
Humanoid.JumpPower = 0
Animation1:Play()
wait(0.5)
CanFly = false
Humanoid.WalkSpeed = 16
Humanoid.JumpPower = 50
CanFly = true
else if Fly == 2 and CanFly == true then
Humanoid.WalkSpeed = 0
Humanoid.JumpPower = 0
Animation2:Play()
CanFly = false
wait(0.5)
Humanoid.WalkSpeed = 16
Humanoid.JumpPower = 50
CanFly = true
else if Fly == 3 and CanFly == true then
Humanoid.WalkSpeed = 0
Humanoid.JumpPower = 0
Animation3:Play()
CanFly = false
wait(0.5)
Humanoid.WalkSpeed = 16
Humanoid.JumpPower = 50
CanFly = true
else if Fly == 4 and CanFly == true then
Humanoid.WalkSpeed = 0
Humanoid.JumpPower = 0
Animation4:Play()
CanFly = false
wait(0.5)
Humanoid.WalkSpeed = 16
Humanoid.JumpPower = 50
CanFly = true
end
end
end
end
end)