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

My animation isn't playing in actual Roblox, but working in Roblox studio?

Asked by 6 years ago
Edited 6 years ago

I have a working animation that plays in Roblox studio, but for some strange reason it won't play in a real server in Roblox.

Here are my scripts:

01wait()
02local CanEmote = true
03local Player = game.Players.LocalPlayer
04local character = Player.Character or Player.CharacterAdded:Wait()
05local Humanoid = character.Humanoid
06local Animation = Humanoid:LoadAnimation(script.Animation)
07 
08script.Parent.MouseButton1Click:Connect(function()
09    if CanEmote then
10    Animation:Play()
11    CanEmote = false
12    wait(1)
13    CanEmote = true
14    end
15end)

Can you help?

0
I will try the scripts out RetroGalacticGamer 331 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

Animations played from a LocalScript replicate to the server, as they are a part of player physics, just like how Humanoid changes replicate to the server. You're getting that error because the character isn't loaded when the player joins the game, you'll have to wait for the character to load.

01wait()
02local Player = game.Players.LocalPlayer
03local character = Player.Character or Player.CharacterAdded:Wait() -- waiting for character
04local Humanoid = character.Humanoid
05local Animation1 = Humanoid:LoadAnimation(script.Animation1)
06local Animation2 = Humanoid:LoadAnimation(script.Animation2)
07local Animation3 = Humanoid:LoadAnimation(script.Animation3)
08local CanEmote = true
09script.Parent.MouseButton1Click:Connect(function()
10    local emote = math.random(1,3)
11    if emote == 1 and CanEmote then -- == true unnecessary 
12        Animation1:Play()
13        CanEmote = false
14        wait(2)
15        CanEmote = true
View all 28 lines...

You should also indent your code properly, some lines were properly indented whilst others weren't. You should also use more local variables, as you didn't need to use them globally as they were defined at the top of the script.

0
Thanks so much! now all I have to do is move the script and change the event! I was stuck on this for a while RetroGalacticGamer 331 — 6y
Ad
Log in to vote
0
Answered by
tantec 305 Moderation Voter
6 years ago

You should put this script in StarterPlayer > StarterCharacterScripts. What this will do will allow the script to load along the character ( the scripts load inside the character model in workspace ) and when you do this instead of using...

1Humanoid = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid")

You should use...

1Humanoid = script.Parent:FindFirstChild("Humanoid")

But you should only use this when you have put the scirpt in the StarterCharacterScripts as it is already in the model which is why I done that.

****Another thing I saw

Also another thing, I was wondering if you wanted the animation to be seeable by other characters seeing as your game was FliteringEnabled, and if you wanted to do this you should use BindableEvents, https://wiki.roblox.com/index.php?title=API:Class/BindableEvent

This allows two scripts to communicate with each other regardless of it being local, server or module and by using this to your advantage, instead of using...

1--Line 09, 16 and 22 btw
2Animation1:Play()

You should use...

1--Wherever you put the BindableEvent, for my example case I put it in ServerStorage
2game:GetService("ServerStorage").BindableEvent:Fire(Animation1) --Sending an argument off

And in another server-script you can receive the firing of the event and play the animation e.g.

1game:GetService("ServerStorage").BindableEvent.Event:connect(function(arg1) -- the arg we sent earlier
2    arg1:Play()
3end)

I hope my answer helped or contributed to you. ~tantec

Answer this question