Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to load animation with remote event?

Asked by 4 years ago
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

Log in to vote
0
Answered by 4 years ago

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)
0
Both of the comments really helpful, I understand what you did. Playing the anim when the even firing smart. thanks AmirGavron -2 — 4y
Ad
Log in to vote
1
Answered by
Dfzoz 489 Moderation Voter
4 years ago
Edited 4 years ago

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

Answer this question