-- Listeners

Tool.Equipped:connect(function()
	
	-- Redefine character and humanoid just in case
	Character = Player.Character
	Humanoid = Character:WaitForChild("Humanoid")
	
	-- Show the segway menu gui and color gui
	NewDisplayGui = DisplayGui:Clone()
	NewDisplayGui.Parent = PlayerGui
	
	NewColorGui = ColorGui:Clone()
	NewColorGui.Parent = PlayerGui
	NewColorGui:WaitForChild("MyTool").Value = Tool
	
	local OpenButton = NewDisplayGui:WaitForChild("OpenButton")
	local ColorOpenButton = NewColorGui:WaitForChild("OpenButton")
	
	OpenButton:TweenPosition(UDim2.new(1, -92,1, -38),0,0,0.4,true)
	ColorOpenButton:TweenPosition(UDim2.new(0, -6,0.5, -70),0,0,0.4,true)
end)

Tool.Unequipped:connect(function() -- Remove segway when tool is unequipped
	game:GetService("ContextActionService"):UnbindAction("segInputAction")
	
	if NewDisplayGui and NewColorGui then
		NewDisplayGui:Destroy()
		NewColorGui:Destroy()
	end
	
	if SpawnedSegway.Value then
		RemoveSegway()
	end
end)

Tool.Activated:connect(function()
	if HasSpawnedSegway.Value == false and IsCoolingDown == false then -- So workspace won't be spammed with segways
	IsCoolingDown = true
	HasSpawnedSegway.Value = true
	
	-- Hide the tool player is holding
	ConfigTool:FireServer(1,Tool,false,nil)
	
	-- Spawn segway
	SpawnSegway:FireServer(Character,Tool,SpawnedSegway,StarterColor.Value) -- Fire remote event to spawn
	
	-- Prevent spamming of segways which may lag the server
	wait(ToolCoolDown)
	IsCoolingDown = false
	end
end)

Humanoid.Died:connect(function()
	RemoveSegway()
end)
