i dont have any code because im not a scripter but im making this game by myself. but anyways i need it so when i press e it plays an animation skjkdasfhdkfhagsdjfasvjaf
Hello!
So if you already have an animation and you exported it then you gotta create LocalScript
inside of StarterPack
, Script
inside of Workspace
and a RemoteEvent
inside of ReplicatedStorage
. You also gotta have an object called Animation
inside of your Script
you just created. Select your Animation
and in the properties change AnimationId to id of your animation. You can find it in the link when you are on the animation's page.
LOCALSCRIPT CODE:
local UIS = game:GetService("UserInputService") --user input service variable local event = game.ReplicatedStorage:FindFirstChild("RemoteEvent") --remote event variable UIS.InputBegan:Connect(function(input, gameProcessed) --function starts when input starts if input.UserInputType == Enum.UserInputType.Keyboard then --checking if user is using keyboard if input.KeyCode == Enum.KeyCode.E then --checking if the key pressed is E event:FireServer() --firing event to the server end end end)
SCRIPT CODE:
game.ReplicatedStorage:FindFirstChild("RemoteEvent").OnServerEvent:Connect(function(player) --getting remote event local hum = player.Character.Humanoid --humanoid variable local anim = script.Animation --animation variable local playing = hum:LoadAnimation(anim) playing:Play() --playing the animation end)
When I tested it out it worked for me, if you will have any troubles, say it.
Put This Script In Starter Character Scripts And Make Sure This Is A Local Script AND The Most Important Thing The Animation Should Be Made By You And No One Else Or Else The Script Wont Work If The Game Is In A Group Publish The Animation Using A Group
local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait() local character = player.Character or player.CharacterAdded:Wait() local Humanoid = character:WaitForChild("Humanoid") local uis = game:GetService('UserInputService') local anim = Instance.new("Animation") anim.AnimationId = "rbxassetid://" -- add ur animation id after the "//" function onKeyPressed(inputObject,gameProcessEvent) if inputObject.KeyCode == Enum.KeyCode.E then -- you can change the key code Humanoid:LoadAnimation(anim):Play() print("Success!") end end uis.InputBegan:Connect(onKeyPressed)