I want the player to start an animation I have made when they click a brick. I have filtering enabled turned on. Here is the LocalScript for them to send the event to start the event/animation
1 | script.Parent.tool.detector.ClickDetector.MouseClick:Connect( function () |
2 | print ( "local script" ) |
3 | script.Parent.animate:FireServer( 2435453180 ) |
4 | print ( "local script" ) |
5 | end ) |
This is the script that receives the event
1 | script.Parent.animate.OnServerEvent:Connect( function (player,animationID) |
2 | local animation = Instance.new( "Animation" ) |
3 | animation.AnimationId = "http://www.roblox.com/Asset?ID=" ..animationID |
4 |
5 | local loadedAnimation = game.Workspace [ player.Name ] .Humanoid:LoadAnimation(animation) |
6 | loadedAnimation:Play() |
7 | print ( "Server script" ) |
8 | end ) |
When I hit play and click the button it does nothing, and the output says nothing.
Playing animations on a player should be done on a local script. If you want to play an animation on NPC (Non-player controlled) then play the animation using a server script.
See more of that here. Look at the bit on "Should I load on Server or Client"
You have the right idea just don't use a server script at all.
In Local Script:
01 | local player = game.Players.LocalPlayer |
02 | local character = player.Character or player.CharacterAdded:Wait() |
03 |
04 | local humanoid = character:WaitForChild( "Humanoid" ) |
05 |
06 | local animationID = 2435453180 |
07 |
08 | local animation = Instance.new( "Animation" ) |
09 | animation.Parent = humanoid |
10 | animation.AnimationId = "http://www.roblox.com/Asset?ID=" ..animationID |
11 |
12 | local part = workspace:WaitForChild( "Part" ) |
13 | local clickDetector = part:WaitForChild( "ClickDetector" ) |
14 |
15 | clickDetector.MouseClick:Connect( function () |
16 | --I believe you can load the animation outside of this function too |
17 | local animTrack = humanoid:LoadAnimation(animation) |
18 | animTrack:Play() |
19 | end ) |
Let me know if you need an explanation for this. It really just is not having to use a server script or RemoteEvents when you don't need to.
edit; property fix & format