Hello, so I created two animations for a basketball game I created but when I attempt to have the user switch the side they are dribbling on (emulating a crossover) when they press “C” nothing happens without an error in the output. Any help is greatly appreciated.
Heres my script:
script.Parent.Anchored = false
local ballHandler = nil
local ball = script.Parent
local lefthandDribbleAnim = script.LeftHandDribble
local righthandDribbleAnim = script.RightHandDribble
local function attachBallToPlayer(player)
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local motor6D = Instance.new("Motor6D")
motor6D.Part0 = humanoidRootPart
motor6D.Part1 = ball
motor6D.C0 = CFrame.new(0, 0, 0)
motor6D.Parent = humanoidRootPart
ball.Anchored = false
ball.CanCollide = false
end
ball.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
ballHandler = player
attachBallToPlayer(player)
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrackLeftHandDribble = animator:LoadAnimation(lefthandDribbleAnim)
local animationTrackRightHandDribble = animator:LoadAnimation(righthandDribbleAnim)
animationTrackLeftHandDribble:Play()
game:GetService("UserInputService").InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.C then
animationTrackLeftHandDribble:Stop()
task.wait()
animationTrackRightHandDribble:Play()
end
end)
end
end
Hey can you just do a print statement between each code after “if input.Keycode…” (other scripter will blame me for this debug but it works for me) just do print(“1”) just keep it simple and tell me what it prints :))
E.g.
-- E.G.
function TheErrorFunction()
print("1")
-- lines that do stuff
print("2")
end
wait(0.1)
print("1")
script.Parent.Anchored = false
print("2")
local ballHandler = nil
local ball = script.Parent
local lefthandDribbleAnim = script.LeftHandDribble
local righthandDribbleAnim = script.RightHandDribble
print("3")
local function attachBallToPlayer(player)
print("4")
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
print("5")
local motor6D = Instance.new("Motor6D")
motor6D.Part0 = humanoidRootPart
motor6D.Part1 = ball
motor6D.C0 = CFrame.new(0, 0, 0)
motor6D.Parent = humanoidRootPart
print("6")
ball.Anchored = false
ball.CanCollide = false
print("7")
end
ball.Touched:Connect(function(hit)
print("8")
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
print("9")
ballHandler = player
attachBallToPlayer(player)
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrackLeftHandDribble = animator:LoadAnimation(lefthandDribbleAnim)
local animationTrackRightHandDribble = animator:LoadAnimation(righthandDribbleAnim)
animationTrackLeftHandDribble:Play()
print("10")
game:GetService("UserInputService").InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.C then
print("11")
animationTrackLeftHandDribble:Stop()
task.wait()
animationTrackRightHandDribble:Play()
print("12")
end
end)
end
end)
Thanks for getting back! here’s a photo of the output: