hello devs! so i have this script that plays a animation at random moments for a skinned mesh but i want to make it so when you click the keybind “R” it plays the animation thats parented to the script and plays a sound along with it heres the script
-- Script for playing animation at random times
local model = script.Parent -- Assuming this script is a child of the model
local PlayAnimationEvent = game.ReplicatedStorage.PlayAnimationEvent -- the remote event
local Hum = model:FindFirstChildOfClass("AnimationController")
local function playAnimation()
-- Get a random animation from the animation controller
local animations = Hum:GetChildren()
local randomAnimation = script:FindFirstChild("Rawr")
-- Play the random animation
Hum:PlayAnimation(randomAnimation)
-- Repeat the process
playAnimation()
end
-- Start playing the animation loop
while true do
playAnimation()
end
PlayAnimationEvent.OnServerEvent:Connect(function()
Hum:LoadAnimation("randomAnimation"):Play() -- animation will play if fireserver
end)
can anyone help out?
heres a photo of where its placed and whats inside of it
local UIS = game:GetService("UserInputService")
local PlayAnimation = game.ReplicatedStorage.PlayAnimationEvent
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R then -- the keycode is r (pressing r)
PlayAnimation:FireServer() -- animation will play
end
end)
yeah i think i need the script remade for me cuz its not printing originally the script was to make it play the animation at a randomwait time so its probably breaking because of that.
This is how you do what you’re looking to do. Drop that in PlayersGUI or PlayerScripts.
Make sure the server script is right and the remote is in the right place and you got it.