Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to load animation with remote event?

local Rep = game:GetService("ReplicatedStorage")
local Event = Rep:WaitForChild("YAS")


Event.OnServerEvent:Connect(function(plr)
	local leaderstats = plr:FindFirstChild("leaderstats")
	leaderstats.Strength.Value += 1 -- Shorthand unary operator for "leaderstats.Strength = leaderstats.Strength + 1"
end)

That's basically the ServerScriptService ( Which add u the stats )

And that's my StarterPlayerScripts

local UIS = game:GetService("UserInputService")

local Replicated = game:GetService("ReplicatedStorage")
local Event = Replicated:WaitForChild("YAS")

UIS.InputBegan:Connect(function(Key)
	if Key.KeyCode == Enum.KeyCode.E then
		Event:FireServer()
	end
end)

So basically as far as I know I gotta add in the ServerScriptService load animation that I made. Idk how to do that, Thanks tho :)

2 answers

✓ Accepted answer

Go ahead and accept the other guys answer but he didnt go into farther detail. I believe you are looking for:

local UIS = game:GetService("UserInputService")

 local anim = Instance.new("Animation")
anim.AnimationId = "ANIMATIONIDHERE"
local animTrack = char.Humanoid:LoadAnimation(anim)


local Replicated = game:GetService("ReplicatedStorage")
local Event = Replicated:WaitForChild("YAS")

UIS.InputBegan:Connect(function(Key)
    if Key.KeyCode == Enum.KeyCode.E then
        Event:FireServer()
 animTrack:Play()

wait(3) - configure to what you want depending on how long the animation plays
AnimTrack:Stop()

    end
end)

1 comment

0

Both of the comments really helpful, I understand what you did. Playing the anim when the even firing smart. thanks

From what I remember animations on your own character can be replicated from the client, so there is no need for playing it server side.

But if you want to play on server or client, you just need to get Player.Character, then its humanoid and get the animation object to load:

local char = player.Character
if char and char:findFirstChild("Humanoid") then
	local anim = Instance.new("Animation")
	anim.AnimationId = "ANIMATIONIDHERE"
	local animTrack = char.Humanoid:LoadAnimation(anim)
	animTrack:Play()
end

This discussion is preserved as it was. New answers, comments, and votes are closed.