Hey, I’m trying to make an animation similar to what a Dragon Ball Ki Charge is. My only problem is that whenever I release the key bind that starts the animation, it doesn’t stop.
I’ve checked the play-test logs and Roblox Studio logs, but nothing appears. Could anyone help me figure out on what’s going on? I have 2 scripts that make it so it appears on both client & server.
Here’s the LocalScript I made called ChargingKi.
local UIS = game:GetService("UserInputService")
local RepStorage = game.ReplicatedStorage
local Remote = RepStorage.KiChange
UIS.InputBegan:Connect(function(input) -- once the script detects an input, it will run
if input.KeyCode == Enum.KeyCode.C then
Remote:FireServer("isCharging")
end
end)
UIS.InputEnded:Connect(function(input) -- similar to "InputBegan", but checks when the input has ended
if input.KeyCode == Enum.KeyCode.C then
Remote:FireServer("isNotCharging")
end
end)
Here’s the normal script I made called KiChargeDetector.
local rs = game.ReplicatedStorage
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://135685597117166"
rs.KiChange.OnServerEvent:Connect(function(player, value) -- when the server receive a value, it will run the code below
local char = player.Character
local track = char:WaitForChild("Humanoid").Animator:LoadAnimation(animation)
if value == "isCharging" then
char:WaitForChild("Humanoid").WalkSpeed = 0
char:WaitForChild("Humanoid").JumpPower = 0
char:WaitForChild("HumanoidRootPart").Anchored = true
track:Play()
end
if value == "isNotCharging" then
char:WaitForChild("Humanoid").WalkSpeed = 16
char:WaitForChild("Humanoid").JumpPower = 50
char:WaitForChild("HumanoidRootPart").Anchored = false
track:Stop()
end
end)
local UIS = game:GetService(“UserInputService”)
local RepStorage = game.ReplicatedStorage
local Remote = RepStorage.KiChange
UIS.InputBegan:Connect(function(input) – once the script detects an input, it will run
if input.KeyCode == Enum.KeyCode.C then
Remote:FireServer(“isCharging”)
end
UIS.InputEnded:Connect(function(input2) – similar to “InputBegan”, but checks when the input has ended
if input2.KeyCode == Enum.KeyCode.C then
Remote:FireServer(“isNotCharging”)
end
end)
end)
local player_tracks = {}
rs.KiChange.OnServerEvent:Connect(function(player, value) -- when the server receive a value, it will run the code below
local char = player.Character
if not(player_tracks[player]) then -- First time adding an AnimationTrack
player_tracks[player] = char:WaitForChild("Humanoid").Animator:LoadAnimation(animation)
end
if value == "isCharging" then
char:WaitForChild("Humanoid").WalkSpeed = 0
char:WaitForChild("Humanoid").JumpPower = 0
char:WaitForChild("HumanoidRootPart").Anchored = true
player_tracks[player]:Play()
end
if value == "isNotCharging" then
char:WaitForChild("Humanoid").WalkSpeed = 16
char:WaitForChild("Humanoid").JumpPower = 50
char:WaitForChild("HumanoidRootPart").Anchored = false
player_tracks[player]:Stop()
end
end)
I’m assuming here that every time the OnServerEvent is received, it will create a new charging animation for the player, meaning you’re only cancelling the newly created one when value == "isNotCharging", and the animation from value == "isCharging" is still playing.
Remember when using animationtracks, you only need to load in the animation once, and then make it :Play() and :Stop(). Hence this is why storing the animation track for each player in a dictionnary player_tracks allows to easily fetch it and play/stop it.
Trying Changing it to this, Also Delete The HumanoidRootPart Anchored Part Since You’re Having the player Speed and Height to 0/ Making The Player Not available To Move
rs.KiChange.OnServerEvent:Connect(function(player, value)
local char = player.Character
local track = char:WaitForChild("Humanoid").Animator:LoadAnimation(animation)
if value == "isCharging" then
char:WaitForChild("Humanoid").WalkSpeed = 0
char:WaitForChild("Humanoid").JumpPower = 0
track:Play()
elseif value == "isNotCharging" then
char:WaitForChild("Humanoid").WalkSpeed = 16
char:WaitForChild("Humanoid").JumpPower = 50
track:Stop()
end
end)
This does fix the issue, but now there’s a new problem… after the keybind is lifted, the animation still plays out until the end. I can’t be sure if this is the script or the animation.
rs.KiChange.OnServerEvent:Connect(function(player, value)
local char = player.Character
local track = char:WaitForChild("Humanoid").Animator:LoadAnimation(animation)
if value == "isCharging" then
char:WaitForChild("Humanoid").WalkSpeed = 0
char:WaitForChild("Humanoid").JumpPower = 0
track:Play()
elseif value == "isNotCharging" then
char:WaitForChild("Humanoid").WalkSpeed = 16
char:WaitForChild("Humanoid").JumpPower = 50
-----------Stops Current Animation
for i,v in pairs(player.Character.Humanoid:GetPlayingAnimationTracks()) do
v:Stop()
end
end
end)