-
What do you want to achieve? I would like to change the idle, walk & run animation ID of the animate script of a player when they equip a tool, and then reset it back to normal when they unequip a tool.
-
What is the issue? Works fine for the client, but other players see bugged animations.
-
What solutions have you tried so far? Did you look for solutions on the Creator Hub? I have looked through many forums however I have not found a solution.
Local Script:
-- [[ SERVICES ]] --
local Players = game:GetService("Players")
local RepStorage = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")
-- [[ VARIABLES ]] --
local plr = Players.LocalPlayer
local backpack = plr:WaitForChild("Backpack")
local serverRemote = RepStorage:WaitForChild("Remotes"):WaitForChild("CutlassEquip")
local toolName = "Tool"
local ToolForEquipping = backpack:FindFirstChild(toolName)
UIS.InputBegan:Connect(function(input, gp)
if gp then return end
if input.KeyCode == Enum.KeyCode.E then
if ToolForEquipping then
serverRemote:FireServer(ToolForEquipping)
end
end
end)
Server Script:
-- [[ SERVICES ]] --
local RepStorage = game:GetService("ReplicatedStorage")
-- [[ VARIABLES ]] --
local serverEvent = RepStorage:WaitForChild("Remotes"):WaitForChild("CutlassEquip")
local humStateEvent = RepStorage:WaitForChild("Remotes"):WaitForChild("HumState")
local originalAnimations = {}
-- [[ EVENT ]] --
serverEvent.OnServerEvent:Connect(function(plr, ToolForEquipping)
local backpack = plr:WaitForChild("Backpack")
local chr = plr.Character or plr.CharacterAdded:Wait()
local hum: Humanoid = chr:WaitForChild("Humanoid")
local animate = chr:WaitForChild("Animate")
local animateIdle: Animation = animate:WaitForChild("idle"):WaitForChild("Animation1")
local animateWalk: Animation = animate:WaitForChild("walk"):WaitForChild("WalkAnim")
local animateRun: Animation = animate:WaitForChild("run"):WaitForChild("RunAnim")
if not originalAnimations[plr] then
originalAnimations[plr] = {
Idle = animateIdle.AnimationId,
Walk = animateWalk.AnimationId,
Run = animateRun.AnimationId
}
end
local animationsFolder = RepStorage:WaitForChild("Animations")
local cutlassIdle = animationsFolder:WaitForChild("CutlassIdle")
local cutlassWalk = animationsFolder:WaitForChild("CutlassWalk")
if ToolForEquipping.Parent == backpack then
hum:EquipTool(ToolForEquipping)
task.wait()
humStateEvent:FireClient(plr, Enum.HumanoidStateType.Freefall)
animateIdle.AnimationId = cutlassIdle.AnimationId
animateWalk.AnimationId = cutlassWalk.AnimationId
animateRun.AnimationId = cutlassWalk.AnimationId
task.wait(0.5)
humStateEvent:FireClient(plr, Enum.HumanoidStateType.Running)
elseif ToolForEquipping.Parent == chr then
hum:UnequipTools()
task.wait()
humStateEvent:FireClient(plr, Enum.HumanoidStateType.Freefall)
animateIdle.AnimationId = originalAnimations[plr].Idle
animateWalk.AnimationId = originalAnimations[plr].Walk
animateRun.AnimationId = originalAnimations[plr].Run
task.wait(0.5)
humStateEvent:FireClient(plr, Enum.HumanoidStateType.Running)
end
end)