Hello can anyone help as to why this code wont work. It is meant to play an animation when I press B. Thanks :D
Main Script:
local UIS = game:GetService("UserInputService") local Player = game.Players.LocalPlayer local Character = Player.Character game.ReplicatedStorage.BBQPressBToUse.OnServerEvent:Connect(function(plr) UIS.InputBegan:connect(function(input) if input.KeyCode == Enum.KeyCode.B then Character.Humanoid.Walkspeed = 16 local Anim = Instance.new("Animation") anim.AnimationId = "rbxassetid://2305757864" local PlayAnim = Character.RightArm:LoadAnimation(Anim) PlayAnim:Play() end end) -- Scripting Helpers: Not completed down below :D UIS.InputEnded:connect(function(input) if input.KeyCode == Enum.KeyCode.B then Character.Walkspeed = 16 end end)
LocalScript (For RemoteEvent)
game:GetService("UserInputService").InputBegan:Connect(function(key) if key.KeyCode == Enum.KeyCode.B then game.ReplicatedStorage.BBQPressBToUse:FireServer() end end)
Thanks ;D
The problem you have is line 11, where you are loading the animation via the character's right arm instead of the humanoid. Here is your server script redone with the changes :) Your Local Script is fine. ALSO NEVER USE USERINPUTSERVICE on the server, that service is client-sided only. Never use the local player and character on the server either, use the player parameter given when firing the remote.
--Server Script --NO USERINPUTSERVICE ON THE SERVER --No LocalPlayer on the server game.ReplicatedStorage.BBQPressBToUse.OnServerEvent:Connect(function(plr) --Don't need the userinput stuff here. local char = player.Character or player.CharacterAdded:Wait() -- Char Variable char.Parent = workspace -- To avoid bugs. char.Humanoid.Walkspeed = 16 local Anim = Instance.new("Animation") anim.AnimationId = "rbxassetid://2305757864" local PlayAnim = char.Humanoid:LoadAnimation(Anim) --Load it on the humanoid. PlayAnim.Priority = Enum.AnimationPriority.Movement --Setting the animation priority. PlayAnim:Play() --Don't need the second end because we don't need the user input twice, especially not on the server. end) --Never Use UserInputService in a server script.