I am making my very own custom animate script
I have a problem: An animation (made of math) plays, when another animation is about to play. It actually doesn’t appear and freezes the previous animation until idle.
I can’t simply just stop the previous RemoteEvent because it probably isn’t possible.
Here’s the code:
- Server:
local Players = game:GetService(“Players”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
Players.PlayerAdded:Connect(function(player)
local ReplicationFolder = Instance.new(“Folder”, ReplicatedStorage.Animator)
ReplicationFolder.Name = player.Name
local IdleAnim = Instance.new("RemoteEvent", ReplicationFolder)
local WalkAnim = Instance.new("RemoteEvent", ReplicationFolder)
IdleAnim.Name = "Idle"
WalkAnim.Name = "Walk"
player.CharacterAdded:Connect(function(character)
local humanoid = character:WaitForChild("Humanoid")
local isMoving = false
local isRunning = false
humanoid.StateChanged:Connect(function(_, newState)
if newState == Enum.HumanoidStateType.Running then
isMoving = true
if isMoving == true then
isRunning = true
WalkAnim:FireAllClients(player)
end
else
if isMoving == false then
isRunning = false
IdleAnim:FireAllClients(player)
end
end
end)
end)
end)
- Local:
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local RunService = game:GetService(“RunService”)
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild(“Humanoid”)
local humanoid = character:WaitForChild(“Humanoid”)
local Torso = character:WaitForChild(“Torso”)
local HRP = character:WaitForChild(“HumanoidRootPart”)
local Motor6D = {
RootJoint = HRP:WaitForChild(“RootJoint”),
Neck = Torso:WaitForChild(“Neck”),
Shoulders = {
LeftShoulder = Torso:WaitForChild(“Left Shoulder”),
RightShoulder = Torso:WaitForChild(“Right Shoulder”)
},
Hips = {
LeftHip = Torso:WaitForChild(“Left Hip”),
RightHip = Torso:WaitForChild(“Right Hip”)
}
}
local remoteEventWalk = ReplicatedStorage.Animator:WaitForChild(player.Name):FindFirstChild(“Walk”)
local remoteEventIdle = ReplicatedStorage.Animator:WaitForChild(player.Name):FindFirstChild(“Idle”)
remoteEventWalk.OnClientEvent:Connect(function()
if humanoid:GetState() == Enum.HumanoidStateType.Running then
local deg = 0
local deg2 = 0
while humanoid:GetState() == Enum.HumanoidStateType.Running do
deg = deg + 1
deg2 = deg2 - 1
local rZ = math.sin(math.rad(deg) * (4)) * 1
local rZ2 = math.sin(math.rad(deg2) * (4)) * 1
local cframe = CFrame.Angles(0, 0, rZ)
local cframe2 = CFrame.Angles(0, 0, rZ2)
Motor6D.Hips.LeftHip.Transform = cframe2
Motor6D.Hips.RightHip.Transform = cframe2
Motor6D.Shoulders.LeftShoulder.Transform = cframe
Motor6D.Shoulders.RightShoulder.Transform = cframe
RunService.Heartbeat:Wait()
end
end
end)
remoteEventIdle.OnClientEvent:Connect(function()
local deg = 0
local deg2 = 0
RunService.Heartbeat:Connect(function()
deg = deg + 1
deg2 = deg2 - 1
local rZ = math.sin(math.rad(deg) * 0.25) * 0.1
local rZ2 = math.sin(math.rad(deg2) * 0.25) * 0.1
local cframe = CFrame.Angles(0, 0, rZ)
local cframe2 = CFrame.Angles(0, 0, rZ2)
Motor6D.Hips.LeftHip.Transform = cframe2
Motor6D.Hips.RightHip.Transform = cframe2
Motor6D.Shoulders.LeftShoulder.Transform = cframe
Motor6D.Shoulders.RightShoulder.Transform = cframe
end)
end)
You can give me an example about how I could approach the problem.
Sorry if the code thingy is a mess, because DevForum likes to mess up the code which makes this effect.