Issues with Converting my tool to Tool6D

For reference, I have been following this resource/tutorial

I wanted to achieve a tool that would play an animation once used, and have two different modes with a separate interaction animation for both different modes. Because of how dissatisfied I was with the regular tools used for tools given by Roblox, I have converted it to Motor6D which only created more problems:

  1. The equip animation stutters before the idle animation plays
    (I used Equip.Ended:Wait() before)
  2. The mode switching doesn’t work anymore or only sometimes
  3. The GUI that appears upon equipping it no longer disappears upon unequipping
  4. The gun (part of the mode switch) doesn’t fully come up, and the animation doesn’t fully play. (It is attached to the torso)

Note: This is a CollectionService local script in StarterCharacterScripts, because there is more than one of this tool I’m trying to make. Additionally, the script is mostly finished, it is just this one part I’m struggling to troubleshoot

Script:

local DebounceToggle = os.clock()
local nextActivate = os.clock()
local debounceTime = 2.2

local ChosenAskAnim = nil
GunActive = false
active = false
CurrentlyHolding = false

-- For sounds
local RegularSounds = Tool:WaitForChild("Sounds")
local ThreatSounds = Tool:WaitForChild("Threat")
local ThankYou = Tool:WaitForChild("Thanks")
local Gosh = Tool:WaitForChild("Rejection")

Tool.Equipped:Connect(function()
	BringItOut:Play() -- Equip animation
	task.wait(0.5)
	LazingAround:Play() -- Idle animation
	print("Equipped"..Tool.name)
	UserInputService.MouseIconEnabled = false
	local ScreenGui = Ui:Clone() -- UI that is supposed to appear on equip
	ScreenGui.Parent = game.Players.LocalPlayer.PlayerGui
	-- toggles the GUI and hides the mouse cursor for convenience
	CurrentlyHolding = true

end)

Tool.Unequipped:Connect(function()
	StopEverything()
	print("Unequipped"..Tool.Name)
	UserInputService.MouseIconEnabled = true
	game.Players.LocalPlayer.PlayerGui:FindFirstChild(Ui.Name):Destroy()
	CurrentlyHolding = false

	-- removes the GUI upon unequip, but it doesn't
end)

--This one checks for a button press which changes the state of the tool
local function ChangeStatus(Input, GameProcessedEvent)

	local BaseGun = game.ReplicatedStorage.Attachments:WaitForChild("Deagle")

	--Debounce check
	if GameProcessedEvent or (os.clock() - DebounceToggle) < 1 then 
		return 
	end

	-- Here, it checks if V is pressed
	-- This also checks to see if the tool is named right.
	if CurrentlyHolding and not active then
		if Input.KeyCode == Enum.KeyCode.V then

			-- "active" checks to see if an animation or voiceline is playing
			-- if a voiceline or animation is still playing, it will not run
			-- may change the key press check for console support
			if not GunActive then
				-- checks if the gun is out
				print("Enabled!")
				GunActive = true
				LazingAround:Stop()
				PackingHeat:Play()
				task.wait(0.5)
				GunIdle:Play()

			else
				print("Disabled!")
				GunActive = false
				-- will fix indicator later
				GunIdle:Stop()
				UnpackingHeat:Play()
				task.wait(0.5)

				LazingAround:Play()

			end
			DebounceToggle = os.clock()
		end
	end
end


-- Events
UserInputService.InputBegan:Connect(ChangeStatus) -- checks if a player presses a button to change the status

Tool.Activated:Connect(function()

	-- checks debounce first
	if os.clock() > nextActivate then
		active = true
		-- "active" makes sure the player is not able to pull out the gun in the middle of the animation and/or voiceline
		nextActivate = os.clock() + debounceTime-- debounce...
		if GunActive then -- when the gun is out, there is no animation
			SignItAlready:Play()
		else
			ChosenAskAnim = math.random(1,2)
			if ChosenAskAnim == 2 then
				SignMyPetition:Play()
			else
				WouldYouPlease:Play()
			end
		end
		local ScreenGui = Asking:Clone() -- the "asking" GUI appears to show when the player can ask again
		ScreenGui.Parent = game.Players.LocalPlayer.PlayerGui
		playSound(ThreatSounds, RegularSounds)
		wait(0.7)
		game.Players.LocalPlayer.PlayerGui:FindFirstChild(Asking.Name):Destroy() -- signal to the player they can ask again
		active = false -- lets the player swap modes, or ask again
	end
end)

If you need more information before helping me, feel free to ask.

2 Likes