I have this code but I’ve been looking at it all day trying to optimize it so there’s no glitching or bugging when the characters changing directions or jumping.
I’ve tried a lot to fix it but it gets stuck in the idle animation sometimes and glitches/flickers when changing directions. when I jump it only play s the jump animation while I am holding down spacebar but I’m trying to make it so you have that animation anytime you’re in the air but the animations overlap, is there some way I can set a priority type of thing up? any help is appreciated, I apologize if my code is messy.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
local Cube = player.Character:WaitForChild("Cube")
local HumanoidRootPart = player.Character:WaitForChild("HumanoidRootPart")
local isButtonPressed = false -- Controls the loop
local IsA = false
local IsD = false
local IsSpace = false
UserInputService.InputBegan:Connect(function(input, processed)
if not processed and input.KeyCode == Enum.KeyCode.A and IsA == false and IsD == false and IsSpace == false then
IsA = true
IsD = false
IsSpace = false
isButtonPressed = true
HumanoidRootPart.Attachment.ParticleEmitter.Rate = 5
task.spawn(function() -- Run the loop in a separate thread
while isButtonPressed == true and IsA == true and IsD == false and IsSpace == false do
-- Line 1 of code
Cube.BillboardGui.ImageLabel.Image = "rbxassetid://86484408230959"
task.wait(0.25) -- Adjust delay as needed
print("step")
-- Line 2 of code
Cube.BillboardGui.ImageLabel.Image = "rbxassetid://134049733657680"
task.wait(0.25) -- Adjust delay as needed
end
end)
end
UserInputService.InputBegan:Connect(function(input, processed)
if not processed and input.KeyCode == Enum.KeyCode.D and IsA == false and IsD == false and IsSpace == false then
isButtonPressed = true
IsA = false
IsD = true
IsSpace = false
HumanoidRootPart.Attachment.ParticleEmitter.Rate = 5
task.spawn(function() -- Run the loop in a separate thread
while isButtonPressed == true and IsA == false and IsD == true and IsSpace == false do
-- Line 1 of code
Cube.BillboardGui.ImageLabel.Image = "rbxassetid://134185848512212"
task.wait(0.25) -- Adjust delay as needed
print("step")
-- Line 2 of code
Cube.BillboardGui.ImageLabel.Image = "rbxassetid://113551294954030"
task.wait(0.25) -- Adjust delay as needed
end
end)
end
UserInputService.InputBegan:Connect(function(input, processed)
if not processed and input.KeyCode == Enum.KeyCode.Space and IsA == false and IsD == false and IsSpace == false then
isButtonPressed = true
IsA = false
IsD = false
IsSpace = true
task.spawn(function() -- Run the loop in a separate thread
while isButtonPressed == true and IsA == false and IsD == false and IsSpace == true and humanoid.FloorMaterial == Enum.Material.Air do
-- Line 1 of code
Cube.BillboardGui.ImageLabel.Image = "rbxassetid://71272473484586"
task.wait(0) -- Adjust delay as needed
print("step")
-- Line 2 of code
script.Jump:Play()
Cube.BillboardGui.ImageLabel.Image = "rbxassetid://71272473484586"
task.wait(0) -- Adjust delay as needed
end
end)
end
end)
end)
end)
UserInputService.InputEnded:Connect(function(input, processed)
local Cube = player.Character:WaitForChild("Cube")
if not processed and input.KeyCode == Enum.KeyCode.A then
isButtonPressed = false
IsA = false
if IsD == true then
task.wait(0.25)
-- Line 2 of code
Cube.BillboardGui.ImageLabel.Image = "rbxassetid://113551294954030"
else if IsSpace == true then
task.wait(.25)
-- Line 2 of code
Cube.BillboardGui.ImageLabel.Image = "rbxassetid://113551294954030"
end
end
--]
end
HumanoidRootPart.Attachment.ParticleEmitter.Rate = 0
Cube.BillboardGui.ImageLabel.Image = "rbxassetid://139582630167371"
wait(0.1)
Cube.BillboardGui.ImageLabel.Image = "rbxassetid://78004517737313"
end)
UserInputService.InputEnded:Connect(function(input, processed)
local Cube = player.Character:WaitForChild("Cube")
if not processed and input.KeyCode == Enum.KeyCode.D then
isButtonPressed = false
IsD = false
end
HumanoidRootPart.Attachment.ParticleEmitter.Rate = 0
Cube.BillboardGui.ImageLabel.Image = "rbxassetid://139582630167371"
wait(0.1)
Cube.BillboardGui.ImageLabel.Image = "rbxassetid://78004517737313"
end)
UserInputService.InputEnded:Connect(function(input, processed)
local Cube = player.Character:WaitForChild("Cube")
if not processed and input.KeyCode == Enum.KeyCode.Space and humanoid.FloorMaterial ~= Enum.Material.Air then
isButtonPressed = false
IsSpace = false
print("Player is on the ground")
Cube.BillboardGui.ImageLabel.Image = "rbxassetid://139582630167371"
wait(0.1)
Cube.BillboardGui.ImageLabel.Image = "rbxassetid://78004517737313"
end
end)
the reason im looping it is because im trying to animate it by making the image id switch from one to another to create a choppy like animation only while that key is help, im not saure if thers a better way to do this?