Issues with Porting Game to Xbox/Controller

So today I tried to put what I had so far on my game to Controller and it kind of broke my game…

Basically I have animations that play when an Input is pressed and they are firing at random with and without the controller being on. I’ve looked on the forum for bugs and things like this but I didn’t find much other than some GameProcessedEvent Bugs.

Video
https://gyazo.com/7e271e473b45c4d688b3ea9a618b8653

Code:

-- Script Is inside the StarterCharacterScripts ///  It's a basketball game btw 




-- Important Objects -- 
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Humanoid = Character:FindFirstChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local AnimationFolder = game.ReplicatedStorage:WaitForChild("GeneralAnimations")
local KeyBoard = Enum.UserInputType.Keyboard
local Controller = Enum.UserInputType.Gamepad1
local BodyAngularVelocity = Instance.new("BodyAngularVelocity",HumanoidRootPart) 
BodyAngularVelocity.MaxTorque = Vector3.new(0,0,0) 
local BodyVelocity = Instance.new("BodyVelocity",HumanoidRootPart)
BodyVelocity.MaxForce = Vector3.new(0,0,0)


-- Services -- 
local ContentProviderService = game:GetService("ContentProvider")
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService") 
local StarterGui = game:GetService("StarterGui") 

-- Client Preloads -- 
local AnimsLoaded = false 
print("PreloadingAssets...")
for i, v in pairs(AnimationFolder:GetChildren())do
	if v:IsA("Animation","Sound") then
		ContentProviderService:PreloadAsync{(v)}
	end
	
end
print("AssetsLoaded!ツ")
AnimsLoaded = true 


-- KeyBoard -- 
local KeyBoard_Controls = {
	MoveBack = Enum.KeyCode.S,
	MoveForward = Enum.KeyCode.W,
	MoveLeft = Enum.KeyCode.A,
	MoveRight = Enum.KeyCode.D,
	Screen = Enum.KeyCode.T,
	Sprint = Enum.KeyCode.LeftShift,
	Guard = Enum.KeyCode.G,
	Jump = Enum.KeyCode.Space,
	Steal = Enum.KeyCode.R,
	Emote = Enum.KeyCode.I,
	SwitchHands = Enum.KeyCode.H,
	DropBall = Enum.KeyCode.P
}

-- Controller  --
local Controller_Controls = {
	Screen = Enum.KeyCode.ButtonL1,
	Sprint = Enum.KeyCode.ButtonR2,
	Guard = Enum.KeyCode.ButtonL2,
	Jump = Enum.KeyCode.ButtonY, 
	Steal = Enum.KeyCode.ButtonX,
	Emote = Enum.KeyCode.DPadDown,
	SwitchHands = Enum.KeyCode.ButtonB,
	DropBall = Enum.KeyCode.DPadRight,
}



--HandleMoves 
local RightDribbleMove = "z"
local LeftDribbleMove = "c"
local BetweenTheLegs = "x"
local BehindTheBackLeft = "cx"
local BehindTheBackRight = "zx"

-- Events --
local PlayerActions = ReplicatedStorage:WaitForChild("PlayerActions")
local Hack = ReplicatedStorage:WaitForChild("Hack")

-- AnimationTracks -- 
local IdleEmote = Humanoid:LoadAnimation(AnimationFolder:WaitForChild("IdleEmote"))
local Screen1 = Humanoid:LoadAnimation(AnimationFolder:WaitForChild("Screen1"))
local Screen2 = Humanoid:LoadAnimation(AnimationFolder:WaitForChild("Screen2"))
local Screen3 = Humanoid:LoadAnimation(AnimationFolder:WaitForChild("Screen3"))
local RightDribble = Humanoid:LoadAnimation(AnimationFolder:WaitForChild("RightDribble"))
local LeftDribble = Humanoid:LoadAnimation(AnimationFolder:WaitForChild("LeftDribble"))
local RightToLeft = Humanoid:LoadAnimation(AnimationFolder:WaitForChild("RightToLeft"))
local LeftToRight = Humanoid:LoadAnimation(AnimationFolder:WaitForChild ("LeftToRight"))
local DropBall = Humanoid:LoadAnimation(AnimationFolder:WaitForChild("DropBall"))
local Pickup = Humanoid:LoadAnimation(AnimationFolder:WaitForChild("Pickup"))

-- Values -- 
local Debounce = true
local Screening, ScreenDebounce = false, true 
local MovingDirection = ""
local WalkSpeedToggled,MovementDebounce = false, true
local AnimationDebounce = true 
local State = "" 
local Ball, Hoop, BallAttach, BallActions, Hand 



-- Game Controls(Input Starting)[NoBall] --  
UserInputService.InputBegan:Connect(function(Input,	GameProcessedEvent)
	if GameProcessedEvent then return end 
	if Character:FindFirstChild("BallAttach") then return end
	
	-- Screen --
	if Input.KeyCode == KeyBoard_Controls.Screen or Controller_Controls.Screen and Screening == false and Debounce and AnimsLoaded and ScreenDebounce then
		
		Debounce = false
		Screening = true 
		ScreenDebounce = false 
		wait()
		
		local RandomScreen = math.random(1,3)
		
		if RandomScreen == 1 then
			Screen1.KeyframeReached:Connect(function(KeyFrame)
				if (KeyFrame == "Hold") then
					Screen1:AdjustSpeed(0)
				end
			end)
			
			Screen1:Play() 
			
		end
		
		if RandomScreen == 2 then
			Screen2.KeyframeReached:Connect(function(KeyFrame)
				if (KeyFrame == "Hold") then
					Screen2:AdjustSpeed(0) 
				end
			end)
			Screen2:Play() 
		end
		if RandomScreen == 3 then
			Screen3.KeyframeReached:Connect(function(KeyFrame)
				if (KeyFrame == "Hold") then
					Screen3:AdjustSpeed(0) 
					
				end
			end)
			
			
			Screen3:Play() 
		end
	end
	
	-- Idle Emote --
	if Input.KeyCode == KeyBoard_Controls.Emote or Controller_Controls.Emote and  Debounce == true and AnimsLoaded == true then
		if Character:FindFirstChild("BallAttach") then return end
		
		
		Debounce = false 
		IdleEmote:Play()
		wait(IdleEmote.Length)
		IdleEmote:Stop()
		Debounce = true 
		
	end
	
	
end)

-- Game Controls(Input Starting)[Ball] --
UserInputService.InputBegan:Connect(function(Input,GameProcessedEvent)
	if GameProcessedEvent then return end 
	
	if Input.KeyCode == KeyBoard_Controls.DropBall or Controller_Controls.DropBall and Character:FindFirstChild("BallAttach") then
		print("DROP")
		
	
		
	end
end)

-- Game Controls(Input Ending) -- 
UserInputService.InputEnded:Connect(function(Input,	GameProcessedEvent)
	if GameProcessedEvent then return end 
	
	-- EndScreen -- 
	if Input.KeyCode == KeyBoard_Controls.Screen or Controller_Controls.Screen and Screening == true and Debounce == false and ScreenDebounce == false then
		
		Debounce = true
		Screening = false
		Screen1:Stop()
		Screen2:Stop()
		Screen3:Stop() 
		
		
		wait(0.5)
		ScreenDebounce = true 
		
	end

end)

-- Ball Add/Remove -- 
Character.ChildAdded:Connect(function(Child)
	if Child:IsA("Motor6D") and Child.Name == "BallAttach" then
		BallAttach = Child
		Ball = BallAttach.Part1
		BallActions = Ball.BallActions 
		Pickup:Play() 
		wait(Pickup.Length) 
		Pickup:Stop()
		RightDribble:Play()
		Hand = "Right"
		StarterGui:SetCore("ResetButtonCallback",false)
		return BallAttach, Ball, BallActions, Hand 
		
	end
end)

Character.ChildRemoved:Connect(function(Child)
	if Child:IsA("Motor6D") and Child.Name == "BallAttach" then
		LeftDribble:Stop()
		RightDribble:Stop() 
		Ball = nil 
		BallActions = nil 
		BallAttach = nil 
		Hand = nil 
		StarterGui:SetCore("ResetButtonCallback",true)

		return Ball, BallActions, BallAttach, Hand 
		
	end
end)


-- Destroy -- 
HumanoidRootPart:WaitForChild("Splash"):Destroy()
HumanoidRootPart:WaitForChild("Landing"):Destroy()
HumanoidRootPart:WaitForChild("Jumping"):Destroy() 
HumanoidRootPart:WaitForChild("GettingUp"):Destroy() 
HumanoidRootPart:WaitForChild("Swimming"):Destroy()
HumanoidRootPart:WaitForChild("FreeFalling"):Destroy()
HumanoidRootPart:WaitForChild("Climbing"):Destroy()

-- DisableStates -- 
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Climbing, false) 
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Swimming, false)
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Flying,false)
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Seated, false)
Humanoid:SetStateEnabled(Enum.HumanoidStateType.RunningNoPhysics, false) 
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, false)
Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
Humanoid:SetStateEnabled (Enum.HumanoidStateType.Seated, false)
Humanoid:SetStateEnabled(Enum.HumanoidStateType.StrafingNoPhysics, false) 
Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)





Btw I tried putting this in Platform Feedback but it didn’t work so I don’t know what’s happening with that either… :neutral_face:

1 Like

Ok… Im dumb don’t mind this…

-- Firstone(Wrongway):
 if Input.KeyCode == KeyBoard_Controls.Screen or Controller_Controls.Screen and Screening == false and Debounce and AnimsLoaded and ScreenDebounce then




--Secondone(rightway):
if Input.KeyCode == KeyBoard_Controls.Screen or Input.KeyCode == Controller_Controls.Screen and Screening == false and Debounce and AnimsLoaded and ScreenDebounce then

-- Important Objects -- 
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Humanoid = Character:FindFirstChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local AnimationFolder = game.ReplicatedStorage:WaitForChild("GeneralAnimations")
local KeyBoard = Enum.UserInputType.Keyboard
local Controller = Enum.UserInputType.Gamepad1
local BodyAngularVelocity = Instance.new("BodyAngularVelocity",HumanoidRootPart) 
BodyAngularVelocity.MaxTorque = Vector3.new(0,0,0) 
local BodyVelocity = Instance.new("BodyVelocity",HumanoidRootPart)
BodyVelocity.MaxForce = Vector3.new(0,0,0)


-- Services -- 
local ContentProviderService = game:GetService("ContentProvider")
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService") 
local StarterGui = game:GetService("StarterGui") 

-- Client Preloads -- 
local AnimsLoaded = false 
print("PreloadingAssets...")
for i, v in pairs(AnimationFolder:GetChildren())do
	if v:IsA("Animation","Sound") then
		ContentProviderService:PreloadAsync{(v)}
	end
	
end
print("AssetsLoaded!ツ")
AnimsLoaded = true 


-- KeyBoard -- 
local KeyBoard_Controls = {
	MoveBack = Enum.KeyCode.S,
	MoveForward = Enum.KeyCode.W,
	MoveLeft = Enum.KeyCode.A,
	MoveRight = Enum.KeyCode.D,
	Screen = Enum.KeyCode.T,
	Sprint = Enum.KeyCode.LeftShift,
	Guard = Enum.KeyCode.G,
	Jump = Enum.KeyCode.Space,
	Steal = Enum.KeyCode.R,
	Emote = Enum.KeyCode.I,
	SwitchHands = Enum.KeyCode.H,
	DropBall = Enum.KeyCode.P
}

-- Controller  --
local Controller_Controls = {
	Screen = Enum.KeyCode.ButtonL1,
	Sprint = Enum.KeyCode.ButtonR2,
	Guard = Enum.KeyCode.ButtonL2,
	Jump = Enum.KeyCode.ButtonY, 
	Steal = Enum.KeyCode.ButtonX,
	Emote = Enum.KeyCode.DPadDown,
	SwitchHands = Enum.KeyCode.ButtonB,
	DropBall = Enum.KeyCode.DPadRight,
}



--HandleMoves 
local RightDribbleMove = "z"
local LeftDribbleMove = "c"
local BetweenTheLegs = "x"
local BehindTheBackLeft = "cx"
local BehindTheBackRight = "zx"

-- Events --
local PlayerActions = ReplicatedStorage:WaitForChild("PlayerActions")
local Hack = ReplicatedStorage:WaitForChild("Hack")

-- AnimationTracks -- 
local IdleEmote = Humanoid:LoadAnimation(AnimationFolder:WaitForChild("IdleEmote"))
local Screen1 = Humanoid:LoadAnimation(AnimationFolder:WaitForChild("Screen1"))
local Screen2 = Humanoid:LoadAnimation(AnimationFolder:WaitForChild("Screen2"))
local Screen3 = Humanoid:LoadAnimation(AnimationFolder:WaitForChild("Screen3"))
local RightDribble = Humanoid:LoadAnimation(AnimationFolder:WaitForChild("RightDribble"))
local LeftDribble = Humanoid:LoadAnimation(AnimationFolder:WaitForChild("LeftDribble"))
local RightToLeft = Humanoid:LoadAnimation(AnimationFolder:WaitForChild("RightToLeft"))
local LeftToRight = Humanoid:LoadAnimation(AnimationFolder:WaitForChild ("LeftToRight"))
local DropBall = Humanoid:LoadAnimation(AnimationFolder:WaitForChild("DropBall"))
local Pickup = Humanoid:LoadAnimation(AnimationFolder:WaitForChild("Pickup"))

-- Values -- 
local Debounce = true
local Screening, ScreenDebounce = false, true 
local MovingDirection = ""
local WalkSpeedToggled,MovementDebounce = false, true
local AnimationDebounce = true 
local State = "" 
local Ball, Hoop, BallAttach, BallActions, Hand 



-- Game Controls(Input Starting)[NoBall] --  
UserInputService.InputBegan:Connect(function(Input,	GameProcessedEvent)
	if GameProcessedEvent then return end 
	if Character:FindFirstChild("BallAttach") then return end
	
	-- Screen --
	if Input.KeyCode == KeyBoard_Controls.Screen or Input.KeyCode == Controller_Controls.Screen and Screening == false and Debounce and AnimsLoaded and ScreenDebounce then
		
		Debounce = false
		Screening = true 
		ScreenDebounce = false 
		wait()
		
		local RandomScreen = math.random(1,3)
		
		if RandomScreen == 1 then
			Screen1.KeyframeReached:Connect(function(KeyFrame)
				if (KeyFrame == "Hold") then
					Screen1:AdjustSpeed(0)
				end
			end)
			
			Screen1:Play() 
			
		end
		
		if RandomScreen == 2 then
			Screen2.KeyframeReached:Connect(function(KeyFrame)
				if (KeyFrame == "Hold") then
					Screen2:AdjustSpeed(0) 
				end
			end)
			Screen2:Play() 
		end
		if RandomScreen == 3 then
			Screen3.KeyframeReached:Connect(function(KeyFrame)
				if (KeyFrame == "Hold") then
					Screen3:AdjustSpeed(0) 
					
				end
			end)
			
			
			Screen3:Play() 
		end
	end
	
	-- Idle Emote --
	if Input.KeyCode == KeyBoard_Controls.Emote or Input.KeyCode ==  Controller_Controls.Emote and  Debounce == true and AnimsLoaded == true then
		if Character:FindFirstChild("BallAttach") then return end
		
		
		Debounce = false 
		IdleEmote:Play()
		wait(IdleEmote.Length)
		IdleEmote:Stop()
		Debounce = true 
		
	end
	
	
end)

-- Game Controls(Input Starting)[Ball] --
UserInputService.InputBegan:Connect(function(Input,GameProcessedEvent)
	if GameProcessedEvent then return end 
	
	if Input.KeyCode == KeyBoard_Controls.DropBall or Input.KeyCode == Controller_Controls.DropBall and Character:FindFirstChild("BallAttach") then
		print("DROP")
		
	
		
	end
end)

-- Game Controls(Input Ending) -- 
UserInputService.InputEnded:Connect(function(Input,	GameProcessedEvent)
	if GameProcessedEvent then return end 
	
	-- EndScreen -- 
	if Input.KeyCode == KeyBoard_Controls.Screen or Input.KeyCode == Controller_Controls.Screen and Screening == true and Debounce == false and ScreenDebounce == false then
		
		Debounce = true
		Screening = false
		Screen1:Stop()
		Screen2:Stop()
		Screen3:Stop() 
		
		
		wait(0.5)
		ScreenDebounce = true 
		
	end

end)

-- Ball Add/Remove -- 
Character.ChildAdded:Connect(function(Child)
	if Child:IsA("Motor6D") and Child.Name == "BallAttach" then
		BallAttach = Child
		Ball = BallAttach.Part1
		BallActions = Ball.BallActions 
		Pickup:Play() 
		wait(Pickup.Length) 
		Pickup:Stop()
		RightDribble:Play()
		Hand = "Right"
		StarterGui:SetCore("ResetButtonCallback",false)
		return BallAttach, Ball, BallActions, Hand 
		
	end
end)

Character.ChildRemoved:Connect(function(Child)
	if Child:IsA("Motor6D") and Child.Name == "BallAttach" then
		LeftDribble:Stop()
		RightDribble:Stop() 
		Ball = nil 
		BallActions = nil 
		BallAttach = nil 
		Hand = nil 
		StarterGui:SetCore("ResetButtonCallback",true)

		return Ball, BallActions, BallAttach, Hand 
		
	end
end)


-- Destroy -- 
HumanoidRootPart:WaitForChild("Splash"):Destroy()
HumanoidRootPart:WaitForChild("Landing"):Destroy()
HumanoidRootPart:WaitForChild("Jumping"):Destroy() 
HumanoidRootPart:WaitForChild("GettingUp"):Destroy() 
HumanoidRootPart:WaitForChild("Swimming"):Destroy()
HumanoidRootPart:WaitForChild("FreeFalling"):Destroy()
HumanoidRootPart:WaitForChild("Climbing"):Destroy()

-- DisableStates -- 
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Climbing, false) 
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Swimming, false)
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Flying,false)
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Seated, false)
Humanoid:SetStateEnabled(Enum.HumanoidStateType.RunningNoPhysics, false) 
Humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, false)
Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
Humanoid:SetStateEnabled (Enum.HumanoidStateType.Seated, false)
Humanoid:SetStateEnabled(Enum.HumanoidStateType.StrafingNoPhysics, false) 
Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)





2 Likes